antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.15k stars 3.28k forks source link

What class of grammars does ANTLR4 support? #3534

Open JoshuaWise opened 2 years ago

JoshuaWise commented 2 years ago

Hello friends,

I have searched the internet far and wide (including as much documentation about ANTLR as I could find), and I couldn't find a single answer for which classes of grammars are supported by ANTLR4 (or even ANTLR3). For example, I know that bison and yacc support LALR(1) grammars, which are well-defined. I know that GLR parsers support all context-free languages. I know that ANTLR uses something called LL(), which I can't find much information on, and yet I see examples of people posting grammars like `expr = expr expr` which is clearly ambiguous. This leads me to ask the following questions:

I saw this quote in the ANTLR4 docs:

ANTLR v4 takes whatever you give it--it just doesn't give a crap

However, I was hoping for a more exact description of the accepted grammar class 😉

mike-lischke commented 2 years ago

ANTLR4 uses an enhanced LL(*) approach. It's called ALL(*) (adaptive LL(*)). The details have been published here: https://www.antlr.org/papers/allstar-techreport.pdf