How Can I Generate an AST from java src code Using ANTLR?
any help?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
OK, here are the steps:
Java.g
and theJavaTreeParser.g
files from here.Run the following commands:
5 files will be generated:
use this java code to generate the Abstract Syntax Tree and to print it:
The setps to generate java src AST using antlr4 are:
Now generate Java8Lexer and Java8Parser using the command:
antlr4 -visitor Java8.g4
This will generate several files such as
Java8BaseListener.java
Java8BaseVisitor.java
Java8Lexer.java
Java8Lexer.tokens
Java8Listener.java
Java8Parser.java
Java8.tokens
Java8Visitor.java
Use this code to generate AST:
After you are done coding you can use gradle to build your project or you can download antlr-4.7.1-complete.jar in your project directory and start compiling.
If you want a the output in a DOT file so that u can visualise the AST then you can refer to this QnA post or directly refer to this repository in which i have used gradle to build the project.
Hope this helps. :)