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
16.68k stars 3.23k forks source link

Error with books source examples in chapter 4 #4609

Open netskink opened 2 months ago

netskink commented 2 months ago

Please include the following information:

Trying to build the .g4 file from the books source examples fails

$ java -jar /Users/davis/progs/github/antlrtesty/jars/antlr-4.13.1-complete.jar -o out  antlr/Java.g4
FAILED: out/antlr 
java -jar /Users/davis/progs/github/antlrtesty/jars/antlr-4.13.1-complete.jar -o out  antlr/Java.g4
error(156): Java.g4:653:35: invalid escape sequence \"

This is the section of Java.g4 which fails with line numbers:

651 fragment
652 EscapeSequence
653     :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
654     |   UnicodeEscape
655     |   OctalEscape
656     ;

It appears the '\" is breaking.

Rebuilding with this line does work but emits multiple warnings.

Mod:

    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\''|'\\')

Warnings:

warning(157): Java.g4:547:14: rule expression contains an assoc terminal option in an unrecognized location
warning(157): Java.g4:548:14: rule expression contains an assoc terminal option in an unrecognized location
warning(157): Java.g4:549:14: rule expression contains an assoc terminal option in an unrecognized location
warning(157): Java.g4:550:14: rule expression contains an assoc terminal option in an unrecognized location
warning(157): Java.g4:551:14: rule expression contains an assoc terminal option in an unrecognized location
warning(157): Java.g4:552:14: rule expression contains an assoc terminal option in an unrecognized location
warning(157): Java.g4:553:14: rule expression contains an assoc terminal option in an unrecognized location
warning(157): Java.g4:554:13: rule expression contains an assoc terminal option in an unrecognized location
warning(157): Java.g4:555:21: rule expression contains an assoc terminal option in an unrecognized location
warning(157): Java.g4:556:25: rule expression contains an assoc terminal option in an unrecognized location
warning(157): Java.g4:557:21: rule expression contains an assoc terminal option in an unrecognized location
warning(157): Java.g4:558:14: rule expression contains an assoc terminal option in an unrecognized location