3 ms·
This can work, but your grammar will be wildly ambiguous. A better way to achieve this is to compose grammars (instead of parsers) and construct the parsers onl
by chriseidhof 16y ago
This can work, but your grammar will be wildly ambiguous. A better way to achieve this is to compose grammars (instead of parsers) and construct the parsers only after the final composition is done.
There is a paper that deals with a very similar problem to this: composing Haskell Read instances. Instead of deriving Read instances for each datatype, they derive grammars, and only produce the parser at the last step. This allows the parser to be optimized. It is a very dense paper, not easy to read but definitely worth it:
http://www.fing.edu.uy/~mviera/papers/VSL08.pdf http://www.fing.edu.uy/~mviera/papers/VSL08.pdf