By Dhruv Agarwal, Ryan Huynh, Adi Pillai, Andrew Chang, and Ashwin Prayaga
We are implementing a basic Python parser using Java
Demo Video: https://youtu.be/O2j6_pOj7tE
ANTLR4 version 4.9.2 ANTLR-Denter (included in repo)
First, download or clone the GitHub repo. Second, open up a terminal in the same directory as the repo.
Add the ANTLR4 and Denter JAR files to your CLASSPATH. (Denter jar file can be moved to a different location than in the repo folder)
- Put the antlr4 file where it belongs
sudo cp antlr-4.9.2-complete.jar /usr/local/lib
- Put the antlr-denter.jar in the correct directory
sudo cp antlr-denter-1.1.jar /usr/local/lib
- Add the antlr-4.9.2-complete.jar file to your bash profile
export CLASSPATH=".:/usr/local/lib/antlr-4.9.2-complete.jar:$CLASSPATH"
- Add the antlr-denter-1.1.jar file to your bash profile
export CLASSPATH=".:/usr/local/lib/antlr-denter-1.1.jar:$CLASSPATH"
- Add alias for antlr4
alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.9.2-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
- Add alias for grun
alias grun='java -Xmx500M -cp "/usr/local/lib/antlr-4.9.2-complete.jar:/usr/local/lib/antlr-denter-1.1.jar:$CLASSPATH" org.antlr.v4.gui.TestRig'
-
Add ANTLR4 and Antlr-Denter to CLASSPATH
-
Create antlr4.bat
java org.antlr.v4.Tool %*
- Create grun.bat
java org.antlr.v4.gui.TestRig %*
- To generate the grammar using ANTLR, direct your terminal to the ParserProjectPoPL directory and run the following command:
antlr4 -Dlanguage=Java popl.g4
- Compile the generated Java classes
javac *.java
- Then, to test the parser on an example file called
test.txt
, run the following commands (-tree for terminal output and -gui for visualization):
Terminal output command:
grun popl start test.txt -tree
Visualization command:
grun popl start test.txt -gui