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" Grammar File and Test
How to create a simple "Hello" grammar file and test it with ANTLR?
✍: FYIcenter
There 4 steps you need to follow to create "Hello" grammar file and test it:
1. Create grammar file, 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
2. Generate the lexer and parser in Java:
\fyicenter>java -cp antlr-4.10.1-complete.jar org.antlr.v4.Tool Hello.g4 \fyicenter>dir 249 Hello.interp 27 Hello.tokens 1305 HelloBaseListener.java 990 HelloLexer.interp 4419 HelloLexer.java 27 HelloLexer.tokens 537 HelloListener.java 4004 HelloParser.java
3. Compile the lexer, parser and supporting Java classes
\fyicenter>javac -cp .;antlr-4.10.1-complete.jar Hello*.java \fyicenter>dir *.class 794 HelloBaseListener.class 3794 HelloLexer.class 304 HelloListener.class 888 HelloParser$RContext.class 4391 HelloParser.class
4. Testing the lexer and parser with ANTLR TestRig:
\fyicenter>java -cp .;antlr-4.10.1-complete.jar org.antlr.v4.gui.TestRig Hello r -tree hello you ^Z (r hello you)
The above output shows that the Hello lexer and parser is working:
⇒ ANTLR "Hello" Lexer and Parser Error
2020-12-02, 7264🔥, 0💬
Popular Posts:
JDK 11 jdk.internal.JVM Stat.jmod is the JMOD file for JDK 11 Internal Jvmstat module. JDK 11 Intern...
What Is wstx-asl-3.2.8.jar? wstx-asl-3.2.8.jar is JAR file for the ASL component of Woodstox 3.2.8. ...
How to download and install ojdbc14.jar for Oracle 10g R2? ojdbc14.jar for Oracle 10g R2 is a Java 1...
JDK 11 java.naming.jmod is the JMOD file for JDK 11 Naming module. JDK 11 Naming module compiled cla...
Apache Avalon began in 1999 as the Java Apache Server Framework and in late 2002 separated from the ...