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, 7262🔥, 0💬
Popular Posts:
What Is ojdbc14.jar for Oracle 10g R2? ojdbc14.jar for Oracle 10g R2 is the JAR files of ojdbc.jar, ...
XML Serializer, Release 2.7.1, allows you to write out XML, HTML etc. as a stream of characters from...
What JAR files are required to run dom\Counter.java provided in the Apache Xerces package? You can f...
How to download and install iText7-Core-7.1.4.zip? iText7-Core-7.1.4.zip is the binary package of iT...
The Web Services Description Language for Java Toolkit (WSDL4J), Release 1.6.2, allows the creation,...