[Haskell-cafe] LL(1) parsing of declarators

Stefan O'Rear stefanor at cox.net
Sat Apr 14 23:52:03 EDT 2007


I'm writing a code generator for C, and I'm trying to parse a C-like
input language using LL(1) (parsec specifically).  The syntax of
declarators is giving me trouble: (simplified)

declaration = qualifiers >> (declarator `sepBy1` char ',')
qualifiers = many1 name
declarator = name

now if we have "<name> <name>", they are both parsed by the greedy
many1 in qualifiers!  I can make this work with some ugly rearranging:

declaration = fdeclarator >> many (char ',' >> declarator)
fdeclarator = name >> many1 name
declarator = name

is there a more elegant way?

Stefan


More information about the Haskell-Cafe mailing list