[Haskell-cafe] Keeping a symbol table with Parsec

Nicolas Frisby nicolas.frisby at gmail.com
Mon Apr 2 18:17:02 EDT 2007


Section 2.12 of the Parsec manual[1] discusses "user state." It sounds
like that is what you are after.

Hope that helps,
Nick

[1] - http://www.cs.uu.nl/~daan/download/parsec/parsec.pdf

On 4/2/07, Joel Reymont <joelr1 at gmail.com> wrote:
> Folks,
>
> Are there any examples of keeping a symbol table with Parsec?
>
> I'm translating a parser from OCaml and I do this
>
> OUTPUT COLON ID LP NUMERIC_SIMPLE RP
>        { add $3 TypNumOut; SimpleOutputDec ($3, Number) }
>
> Meaning that if a keyword Output is followed by ":" and an identifier
> and then "(NumericSimple)" then add identifier to the symbol table as
> a Number and box it in a constructor.
>
> Then in my lexer I do a lookup to check if I have seen this
> identifier and if I have seen one of type TypeNumOut I return the
> token NUM instead of ID. This ensures that I can have rules with the
> token NUM as opposed to ID everywhere.
>
> How would I accomplish the same with Parsec, that is 1) update a
> symbol table and 2) check identifiers and "return a different token"?
>
>         Thanks, Joel
>
> --
> http://wagerlabs.com/
>
>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list