Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
ANTLR "Hello" Lexer and Parser Error
How to test the "Hello" lexer and parser with invalid source code? I have created the "Hello" grammar and generated the "Hello" lexer and parser.
✍: FYIcenter
To test the "Hello" lexer and parser with invalid source code,
we need to review the "Hello" grammar again.
\fyicenter>more hello.g4 // Define a grammar called Hello grammar Hello; r : 'hello' ID ; // match keyword hello followed by an identifier ID : [a-z]+ ; // match lower-case identifiers WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
The "Hello" grammar file contains:
So the following source code lines should be valid:
hello you hello there hello hello
And the following source code lines are invalid:
Hello you hello you! hello Joe hello 123
If you run the TestRig with invalid source code lines, you will get syntax errors from the parser:
\fyicenter>java -cp .;antlr-4.10.1-complete.jar org.antlr.v4.gui.TestRig Hello r -tree Hello you ^Z line 1:0 token recognition error at: 'H' line 1:1 missing 'hello' at 'ello' (r <missing 'hello'> ello) \fyicenter>java -cp .;antlr-4.10.1-complete.jar org.antlr.v4.gui.TestRig Hello r -tree hello you! ^Z line 1:9 token recognition error at: '!' (r hello you) \fyicenter>java -cp .;antlr-4.10.1-complete.jar org.antlr.v4.gui.TestRig Hello r -tree hello Joe ^Z line 1:6 token recognition error at: 'J' (r hello oe) \fyicenter>java -cp .;antlr-4.10.1-complete.jar org.antlr.v4.gui.TestRig Hello r -tree hello 123 ^Z line 1:6 token recognition error at: '1' line 1:7 token recognition error at: '2' line 1:8 token recognition error at: '3' line 2:0 missing ID at '<EOF>' (r hello <missing ID>)
⇒ ANTLR TestRig Graphical Output
2020-12-02, ∼7588🔥, 0💬
Popular Posts:
What Is jsse.jar (JDK 6) Java Secure Socket Extension? jsse.jar, Java Secure Socket Extension, is Ja...
What Is poi-ooxml-5.2.3.jar? poi-ooxml-5.2.3.jar is one of the JAR files for Apache POI 5.2.3, which...
What Is junit-3.8.1.jar? junit-3.8.1.jar is the version 3.8.1 of JUnit JAR library file. JUnit is a ...
commons-collections4-4.4 -sources.jaris the source JAR file for Apache Commons Collections 4.2, whic...
JDK 11 jdk.localedata.jmod is the JMOD file for JDK 11 Localedata module. JDK 11 Locale Data module ...