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

Lennart Augustsson lennart at augustsson.net
Sun Apr 15 02:42:02 EDT 2007


But the qualifiers aren't arbitrary names, are they?

On Apr 15, 2007, at 04:52 , Stefan O'Rear wrote:

> 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
> _______________________________________________
> 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