Replies: 1 comment 1 reply
-
When writing a compiler from scratch, one often bootstraps a bit of the code. Once the compiler is working at a basic level, the bootstrap code is replaced with code written in the language targeted by the compiler. We do that because we want to "think" in that language. Antlr4 is written in Antlr3, but the bootstrap layer (Antlr3) was never rewritten in Antlr4 because there wasn't a tool to convert the Antlr3 grammar into Antlr4. It wasn't a priority. As a "consolation prize," the antlr4 grammar was written. It works for third-party tooling, e.g., formatting, linting, grammar coverage, and Antlr4 grammar editor plugins. Along with the grammars in gramamrs-v4, these tools are as important as the parser generator itself. While we assume that the Antlr4 grammar is correct, time and again the assumption has been proven to be wrong. antlr/grammars-v4#3815. The Antlr5 parser could be written by hand, but we will need "an official Antlr5 grammar" for tooling. It allows one to reason about the parse tree. Grammars concisely describes that structure; a verbose, natural language description along with a hand-written parser in any language alone cannot suffice. |
Beta Was this translation helpful? Give feedback.
-
Maybe it's sounds a bit strange but I suggest writing grammar lexer and parser by hand. It provides the following benefits:
I started work at this direction some time ago:
LeftRecursiveRuleWalker.g
without affecting functionality but with code simplification, see MR to my ANTLR fork: Left recursion fixes KvanTTT/antlr4#6. It's worth mention that this MR removes more lines than adds (-200).Beta Was this translation helpful? Give feedback.
All reactions