Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
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 (309)
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, 7096🔥, 0💬
Popular Posts:
JDK 11 jdk.jdi.jmod is the JMOD file for JDK 11 JDI (Java Debug Interface) tool. JDK 11 JDI tool com...
What Is poi-3.5.jar - Part 2? poi-3.5.jar is one of the JAR files for Apache POI 3.5, which provides...
JDK 11 jdk.crypto.mscapi.jmod is the JMOD file for JDK 11 Crypto MSCAPI module. JDK 11 Crypto MSCAPI...
ASM is an all purpose Java bytecode manipulation and analysis framework. It can be used to modify ex...
Java Cryptography Extension 1.6 JAR File Size and Download Location: File name: jce.jar, jce-1.6.jar...