Java Tree parser output for ANTLR

后端 未结 2 1378
自闭症患者
自闭症患者 2020-12-09 07:18

I\'ve found a sample template in the ANTLR website, its the Javatreeparser.g, which the site says could produce the AST that I need, but since I\'m new to ANTLR, how do I ma

2条回答
  •  萌比男神i
    2020-12-09 08:04

    I really recommend you to use antlr4.

    First, set your CLASSPATH (including antlr-4.5.3-complete.jar) and JAVA_HOME.

    Second, generate a lexer and parser from the grammar Java.g4:

    java -cp antlr-4.5.2-complete.jar Java.g4
    

    Third, compile all Java*.java genereated:

    javac Java*.java
    

    Finally, run TestRig:

    java org.antlr.v4.runtime.misc.TestRig Java compilationUnit -gui Test.java
    

    You will see AST visually as follows:

提交回复
热议问题