Support:

Build java files from grammar

  1. Download and install ANTLR tool.
  2. In grammars directory, execute the following command for each or both grammars
    #antlr Php.g
    #antlr PhpTree.g
    or
    #antlr Php.g PhpTree.g
  3. 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.

  1. Download and install ANTLR tool, Ant and JDK.
  2. Inside the tool directory, execute the following command
    #ant build
  3. Now you can use them:
    - copying the directory build/classes/org
    or
    - 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
    import org.homeunix.awap.php.parser.*;

Build and run tool

  1. Download and install ANTLR tool and JDK.
  2. Inside the PhpParser tool directory, compile the java main file PhpParser
    #javac -classpath $CLASSPATH:build/classes PhParser.java
  3. 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.