- Introduction
- Context-free grammar
- Write a grammar
- Some issues
- Step 1: Exporting classpath of the jar and creating alias
# Exporting classpath of the jar and creating alias
$ export CLASSPATH=".:path_to/antlr-*-complete.jar:$CLASSPATH"
$ alias antlr4='java -Xmx500M -cp "path_to/antlr-*-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
$ alias grun='java org.antlr.v4.runtime.misc.TestRig'
- Step 2: Testing if jar is accessible or not
$ java org.antlr.v4.Tool
# or
$ java -jar path_to/antlr-*-complete.jar
# or
$ antlr4
If it shows:
ANTLR Parser Generator Version 4.7
so on ...
then it was successful
- Step 3: Running the antlr tool on file
$ antlr4 MC.g4
It will auto generate files *.tokens *.java
- Step 4: Compile all the java files by
$ javac MC*.java
- Step 5: Draw parser tree by following command:
$ grun MC program -f path_to/test.txt -gui
Now, we have the parse tree as shown below