Compiler Course Project Fall-2019
Thanks to AliReza Heydari
graphviz is used to plot syntax tree of input file
$ sudo apt install graphviz
source of installation is https://github.com/antlr/antlr4
- Install Java (version 1.6 or higher)
- Download
$ cd /usr/local/lib
$ curl -O https://www.antlr.org/download/antlr-4.7.1-complete.jar
Or just download in browser from website:
https://www.antlr.org/download.html
and put it somewhere rational like /usr/local/lib
.
- Add
antlr-4.7.1-complete.jar
to yourCLASSPATH
:
$ export CLASSPATH=".:/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH"
It's also a good idea to put this in your .bash_profile
or whatever your startup script is.
- Create aliases for the ANTLR Tool, and
TestRig
.
$ alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
$ alias grun='java -Xmx500M -cp "/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH" org.antlr.v4.gui.TestRig'
Either launch org.antlr.v4.Tool directly:
$ java org.antlr.v4.Tool
ANTLR Parser Generator Version 4.7.1
-o ___ specify output directory where all output is generated
-lib ___ specify location of .tokens files
...
or use -jar option on java:
$ java -jar /usr/local/lib/antlr-4.7.1-complete.jar
ANTLR Parser Generator Version 4.7.1
-o ___ specify output directory where all output is generated
-lib ___ specify location of .tokens files
...
NOTE: this step is optional!
After installing antlr4
you should generate lexer and parser codes using antlr4
.
Use the following command:
$ antlr4 -Dlanguage=Python3 MiniJava.g4
to install the requirements of project use following command:
$ pip install -r requirements.txt
show help:
$ python3 Project.py -h
The flag --ast
stores Abstract Syntax Tree in output
directory.
the flag --cst
stores Complete parse tree in output
directory.
Examples:
$ python3 Project.py -i testfiles/Factorial.java --ast --cst