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, ∼7533🔥, 0💬
Popular Posts:
Apache Log4j 1.2 Bridge allows applications coded to use Log4j 1.2 API to use Log4j 2 instead. Bytec...
Java Cryptography Extension 1.6 JAR File Size and Download Location: File name: jce.jar, jce-1.6.jar...
What Is jtds-1.2.2.jar? jtds-1.2.2.jar is the JAR files of jTDS Java library 1.2.2, which is a JDBC ...
layout.jar is a component in iText Java library to provide layout functionalities. iText Java librar...
JDK 11 jdk.jlink.jmod is the JMOD file for JDK 11 JLink tool, which can be invoked by the "jlink" co...