kendomino
u/kendomino
Over the years, people found out that this claim is not true. Many grammars in https://github.com/antlr/grammars-v4 contain ambiguities and/or large max-k's (from not left factoring) that just kill performance. It is also the case that Antlr4 sometimes chooses the wrong parse out of all possible derivations. Some EBNFs need a symbol table to disambiguate. Examples I recently worked on: https://github.com/antlr/grammars-v4/tree/master/c; https://github.com/antlr/grammars-v4/tree/master/ada/ada2012. Write your grammar as is, but periodically check for ambiguity and max-k's. Note, there is a PL1 subset here, but I haven't tested it much: https://github.com/antlr/grammars-v4/tree/master/pl0 . You might also read the GitHub thread at https://github.com/antlr/grammars-v4/issues/1752 .
It handles left-recursion. Under the covers, it performs the usual refactoring to remove the recursion, then constructs the proper tree on the way out so that it corresponds to the original grammar.
However, make sure to really use the tools to determine ambiguity and unfactored rules after you get the parser working. These can cause the parse to be non-linear.
Depending on what language you want to parse, I'd recommend using a parser generator like Antlr4. It outputs a CST. Unfortunately, with Antlr CSTs, off-channel content (whitespace, comments, etc.) is not included in the CST. This is why I convert the Antlr CSTs into DOM, decorating the DOM with the off-channel content as attributes. You can then use standard tools to manipulate the DOM. The main problem with Antlr is that people don't know how to write good grammar.
I am old fashioned, i.e. I am old and retired. It's bare boot or crampons or snowshoes. That's what I grew up with. I also ice climb which is mostly front pointing. I cannot stand microspikes. Only time I do use MS is in shoulder seasons, where I don't care trashing them. I stick to mostly packed trails so snowshoes are rare. Once trails are covered with snow, crampons are on just outside the car for the entire hike. I have very large feet, and when I use my Olympus Mons, essentially it's like wearing snowshoes, but with better freedom. Comes in handy cause I have a wide stance, too, as many trails are broken in a narrow width. I use the "tap tap tap" technique to stop postholing.
I tested the grammar at https://github.com/orneryd/Mimir/tree/334e79ac2d60417b19d32d84fb59ea0491ee2ab9/nornicdb/pkg/cypher/antlr using the Trash Toolkit ( https://github.com/kaby76/Trash ). The grammar is similar enough to that at https://github.com/antlr/grammars-v4/tree/0f2069ec471e77cf4a8c6c0a950595586d825434/cypher, so I used the test suite in grammars-v4 to validate your grammar. While it has no ambiguity, it does have max-k's that stretch for nearly the entire length of a Cypher statement. I recommend left factoring the grammar.