[Haskell-cafe] Keeping a symbol table with Parsec
Joel Reymont
joelr1 at gmail.com
Mon Apr 2 17:48:30 EDT 2007
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/
More information about the Haskell-Cafe
mailing list