Build java files from grammar
- Download and install ANTLR tool.
- In grammars directory, execute the following command for each or both grammars
#antlr Php.g PhpTree.g
- ANTLR will create the necessary java files for each grammar in the present directory.
Now you can use them in your projects
If you want to modify the grammars and use the PhpParser tool with these modifications or build the whole
tool (grammars and java files) you can follow the next steps. This way you will create a directory
struture suitable to use in futher projects.
- Download and install ANTLR tool,
- Inside the tool directory, execute the following command
- Now you can use them:
- copying the directory build/classes/org
- importing all the jar files from the directory dist
into your project and make it parent directory part of your classpath.
Add the following import statement to the Java files which shall invoke PhpParser
Build and run tool
- Download and install ANTLR tool and
- Inside the PhpParser tool directory, compile the java main file PhpParser
#javac -classpath $CLASSPATH:build/classes PhParser.java
- Execute it by typing
#java -classpath $CLASSPATH:build/classes:. PhParser file1.php < file_n.php >
you can pass -dot option to generate DOT diagram for AST. To use that, you will need
install dot, from Graphviz site.