antlr 4.2.2 output to console warning (157)
Asked Answered
F

1

6

I downloaded latest release of ANTLR - 4.2.2 (antlr-4.2.2-complete.jar) When I use it to generate parsers for grammar file Java.g4 it prints me some warnings like: "Java.g4:525:16: rule 'expression' contains an 'assoc' terminal option in an unrecognized location"

Files was generated but didn't compile

Previous version works fine.

Whats wrong?

Forepeak answered 29/4, 2014 at 8:25 Comment(1)
This problem (with the Java.g4 file that comes with the source code zip file for the book The Definitive ANTLR 4 Reference (The Pragmatic Bookshelf, January 2013)) persists, amazingly enough, deep into 2022. There are also pretty ugly lines in the example code and deprecation warnings. That book needs a "revised edition".Golgi
M
16

The <assoc> should now be moved left of the "expression".

It must be placed always right to the surrounding |:

Look here: https://theantlrguy.atlassian.net/wiki/display/ANTLR4/Left-recursive+rules

 ...
 |   expression '&&' expression
    |   expression '||' expression
    |   expression '?' expression ':' expression
    |<assoc=right>   expression
        (   '='
        |   '+='
        |   '-='
        |   '*='
        |   '/='
        |   '&='
        |   '|='
        |   '^='
        |   '>>='
        |   '>>>='
        |   '<<='
        |   '%='
        )
        expression
Moir answered 29/4, 2014 at 8:51 Comment(4)
and how do you get access to "theantlrguy" ?Clari
@WeaponX seems it is no longer publicMoir
Maybe it can now be found on GitHub. github.com/antlr/antlr4/blob/master/doc/left-recursion.mdMoir
Confirmed. Search for assoc on this pageMoir

© 2022 - 2024 — McMap. All rights reserved.