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 Parser Java API
Where is ANTLR API for Java integration?
✍: FYIcenter
ANTLR API for Java is available at
https://www.antlr.org/api/Java/.
To integrate the lexer and parser generated from ANTLR into your Java application, you can follow these steps:
1. Create a character stream (org.antlr.v4.runtime.CharStream) object from the your source code string to be parsed with the org.antlr.v4.runtime.CharStreams.fromString() method. For example:
CharStream stream = CharStreams.fromString("x = a");
2. Create your own lexer object from the character stream. For example:
arithmeticLexer lexer = new arithmeticLexer(stream);
3. Create a token stream (org.antlr.v4.runtime.CommonTokenStream) object from your lexer. For example:
CommonTokenStream tokens = new CommonTokenStream(lexer);
4. Create your own parser object from the token stream. For example:
arithmeticParser parser = new arithmeticParser(tokens);
5. Create a syntax tree (org.antlr.v4.runtime.tree.ParseTree) object by calling the grammar rule as a parser method. For example:
ParseTree tree = parser.equation();
6. Dump the syntax tree in LISP style. For example:
System.out.println(tree.toStringTree(parser));
If there is any syntax error in the source code, the parser.equation() method will generated error messages to the console.
⇒ ANTLR "Arithmeic" Grammar Java Test
2020-12-26, ∼7538🔥, 0💬
Popular Posts:
commons-io-2.6-sources.j aris the source JAR file for Apache Commons IO 2.6, which is a library of u...
JDK 17 java.xml.crypto.jmod is the JMOD file for JDK 17 XML (eXtensible Markup Language) Crypto modu...
maven-settings-builder-3 .8.6.jaris the JAR file for Apache Maven 3.8.6 Settings Builder module. Apa...
What Is jms.jar? I heard it's related to JMS (Java Message Service) 1.1? The if you have an jms.jar ...
What Is ojdbc7.jar for Oracle 12c R1? ojdbc7.jar for Oracle 12c R1 is the JAR files of ojdbc.jar, JD...