#Wolf
##Description
Wolf is my simple programming language which is created using ANTLR parser generator. For more information about ANTLR, visit ANTLR Wikipedia. This is a effort of learning and knowing more about how languages are made by creating a simple programming language.
I am using Gradle ANTLR Plugin for build. Here we have given input file which is example.wlf in gradle.build task.
- To build and compile our class with our generated parser, run
sh run.sh -b
Get parsed data from file input
- To visualize the AST in gui, run
sh run.sh -guiORsh run.sh -gui filename - To visualize AST as tokens, run
sh run.sh -tokensORsh run.sh -tokens filename - To visualize AST as tree, run
sh run.sh -treeORsh run.sh -tree filename
In above running options filename is optional. By default above commands will take example.wlf sample file as input.
Giving input from console
- To visualize the AST in gui, run
sh run.sh -guic - To visualize AST as tokens, run
sh run.sh -tokensc - To visualize AST as tree, run
sh run.sh -treec
After running any of the above script. It will ask for input on console. For example:
$ sh run.sh -tokensc
Enter input string to parse and press ctrl+z (Windows) or ctrl+d (Unix based OS):
12-2*(5/10)-1**2Now press ctrl+d or ctrl+z to see the output after giving input.
[@0,0:1='12',<10>,1:0]
[@1,2:2='-',<7>,1:2]
...................
...................
[@14,17:16='<EOF>',<-1>,2:0]By default sh run.sh without any option runs in -guic mode. Means, it will take input from console and give AST in gui.
- We are using our generated parser in
Wolf.javaclass. We are usingEvalVisitor.javaclass to extendWolfBaseVisitor<Integer>class. To implement the calculator, we override the methods associated with statement and expression alternatives. To run all compiled classes along with our generated parser, run
$ sh run.sh -a
## Running...
Enter data and press ctrl+d(Unix based OS) or ctrl+z(Windows) to see the output:
a=4
b=10
c=a+b
b=a
c
b
Output:
14
4OR
Now pass input from a file. Here it is example.wlf and this is the content in it:
193
a=5
b=6
a+b*2
(1+2)*3Now run it.
$ sh run.sh -a example.wlf
## Running...
193
17
9