3 ms·
This is a good point in favour of context free grammar based parser generators. I think the trade-off is a bit more subtle though. CFG semantics is nice and de
by jules 5y ago
This is a good point in favour of context free grammar based parser generators. I think the trade-off is a bit more subtle though.
CFG semantics is nice and declarative when we specify which strings belong to the language, but a parser is a function from strings to parse results, and then the nice semantics stops working due to ambiguities.
The PEG semantics on the other hand naturally expresses such a function, and the function you get with PEG semantics is almost always the function you want.
When we look at character level grammars, the CFG formalism doesn't work well either. They fundamentally rely on greedy lexical token matching.
Extensions such as indentation sensitive parsing and user defined operators quite naturally fit into PEG style semantics, and are more difficult to integrate into CFGs.
CFG based parser generators are way more complicated internally than PEG based parser generators, which are extremely simple.
- orlp 5y ago> The grammar may not be exactly what you want to illustrate your point (I think you want to swap the two sides of the /) No, I think you might be misunderstanding my point. For example, if you think the grammar I posted matches aaaaa, you'd be wrong.
- jules 5y agoYes you're right, I had already edited that while you were posting your reply. I thought you wanted to point out the usual simple "a" / "aa" problem.