3 ms·
At least according to wikipedia, ANTLR accepts a CFG (context free grammar), while PEG (parsing expression grammar) is not context free, specifically, the choic
by intrepidhero 4y ago
At least according to wikipedia, ANTLR accepts a CFG (context free grammar), while PEG (parsing expression grammar) is not context free, specifically, the choice operator in a PEG selects the first match.
I've been reading about parsers recently (https://www.craftinginterpreters.com/contents.html https://www.craftinginterpreters.com/contents.html and https://peps.python.org/pep-0617/ https://peps.python.org/pep-0617/). It seems like recursive descent parsers are considered a little easier to reason about, and PEG aligns well with recursive descent.
I have not yet dived deeper in yacc, bison, or ANTLR and how you would write a parser from a CFG. Can anyone add their experiences?
- difflens 4y agoFWIW, here's a repo of ANTLR grammars: https://github.com/antlr/grammars-v4 https://github.com/antlr/grammars-v4 Many of them are incomplete, but it gives a good idea of how the grammar looks for ANTLR. I used the ANTLR grammar for parsing CSS in DiffLens (https://github.com/marketplace/difflens https://github.com/marketplace/difflens). DiffLens uses the typescript compiler itself to parse TS and JS. I've also used Roslyn to parse C# (and F#). I wonder if the ruby compiler itself exposes a parser.