This repo is a simple calculator implemented with ANTLR4 and Python3.
This project is inspired by 编译原理之美, which is a Course Design of Compiling using ANTLR4.
Follow the instruction on Antlr4.
cd /usr/local/lib
sudo curl -O https://www.antlr.org/download/antlr-4.8-complete.jar
export CLASSPATH=".:/usr/local/lib/antlr-4.8-complete.jar:$CLASSPATH"
alias antlr4='java -jar /usr/local/lib/antlr-4.8-complete.jar'
alias grun='java org.antlr.v4.gui.TestRig'
Details can be found in python-target.
pip3 install antlr4-python3-runtime
antlr4 -Dlanguage=Python3 PlayScript.g4 -visitor -o dist
Use -visitor
to generate Visitor Class
Use -o
to specify output path.
python3 main.py