Ryan Avery

Interpreter


I created this interpreter during the Fall semester of 2016 for my CS-354, Programming Languages class at Boise State University. An interpreter is a program that takes a relatively high level set of instructions and translates them into a lower level set of instructions which are then executed. This is done in real time whenever the higher level instructions are run, so although it has lower upfront costs, it is also not as fast as running the outputlarge project picture of a compiled program.

This particular interpreter has a relatively complete set of grammar which can be seen in the image accompanying this page (which you can click to enlarge). It allows for statements such as if-else statements, do-while statements, and many other things that we have come to expect in most programming languages. It does not, however, allow for classes or the usage of libraries, as this was not in the scope of this class, but I do think it would have been fun to incorporate those into this project.

In order to use this program, a list of instructions can be given as space-separated command line arguments, or the name of a file with line separated commands can be given as the only argument. A valid file, for instance, could have this as its content:

rd a;
rd b;
while a<>b do
    if a>b then
        a=a-b
    else
        b=b-a;
wr a;

This program would ask the user to input two numbers and then it would output their greatest common factor. The interpreter does this by first creating a parse tree of the source code and then converting this into valid java code. Once this is done, the environment which is created gets executed in Java.