I've recently taken to reading some literature on the compilation of functional languages and I would like some insight into how the parsing of the commonly-given EBNF grammar for, say, expressions is actually resolved.
For example, in a simple lambda calculus with constants:
expr ::=
var
| literal
| 'λ' var '.' expr
| expr expr
| '(' expr ')'
The case I'm concerned with is application; expr expr
, which is both left and right recursive. How do parser implementors resolve this? For the purpose of the question, I'm mostly wondering about parser generators such as bison (I know that ANTLR seems to do some trickery to resolve this case).
Is it possible to factor this out? Is there a structured way to resolve this kind of ambiguity or is it purely heuristic? I gather that OCaml uses a parser-generator for its grammar but I've not been able to dissect it enough to understand what's going on.
Any insight would be much appreciated.