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, 7157🔥, 0💬
Popular Posts:
JRE 8 rt.jar is the JAR file for JRE 8 RT (Runtime) libraries. JRE (Java Runtime) 8 is the runtime e...
What Is javaws.jar in JRE (Java Runtime Environment) 8? javaws.jar in JRE (Java Runtime Environment)...
Where to find answers to frequently asked questions on Downloading and Using JDK (Java Development K...
JDK 8 tools.jar is the JAR file for JDK 8 tools. It contains Java classes to support different JDK t...
What Is ojdbc7.jar for Oracle 12c R1? ojdbc7.jar for Oracle 12c R1 is the JAR files of ojdbc.jar, JD...