4 ms·
PEG/parser combinators + Pratt has many advantages over LR: 1. It's faster 2. It's quite high level, arguably higher level than LR 3. Can more easily support
by jules 6y ago
PEG/parser combinators + Pratt has many advantages over LR:
1. It's faster
2. It's quite high level, arguably higher level than LR
3. Can more easily support good error messages
4. Can easily escape hatch into the surrounding Turing complete programming language, so you can parse anything
5. Does character level parsing, so no lexer required, and easily supports parsing sublanguages, e.g. regex literals inside another programming language
6. Can make use of the abstraction facilities of the surrounding programming language
7. No shift/reduce errors
8. The whole parsing stack is WAY simpler than LR
The main advantages of LR are:
1. Its theory is nicer because CFGs have nicer denotational semantics
2. It perhaps supports better automatic error recovery
Anything I forgot?
P.S. whether CFGs are actually a good formalism for programming languages is debatable. At the character level, most programming languages grammars are not context free. So the context freeness depends on the non context freeness of the lexer. It's fine to use a lexer of course (as long as you do not need to combine multiple languages), but this observation makes CFGs lose some of their theoretical appeal, imo. Character level CFG parsers have some non context free extensions to actually parse the things we want to parse.