GSC Interpreter
A Turing-complete interpreter developed for a compiler course
|
This is an interpreter for a simple Turing-complete programming language (SC) with a syntax similar to C. It was developed as part of the course Language and Compilers of the Computer Science degree at FAMAF, UNC.
To use and run the interpreter, you only need to have g++ installed on your system. The requirement is pretty simple, as g++ is the standard C++ compiler on most systems.
To work with GSC, you can clone the repository and compile it:
Before compiling, you have two options to use GSC: interactive or file mode. For the first one, you can run the interpreter without any arguments:
And for the second one, you can pass a file as an argument:
There are some tests for each implemented module in the test
directory. It was made with the use of Catch2, a C++ testing framework. You can run them with the following command:
Also, there're an automatic documentation generated with Doxygen for the project and it's published in the corresponding GitHub Pages site: docs.
Some program examples in SC language are provided in the examples
directory. There are programs like fibonacci and MCD calculators, prime number checker, and more.
The grammar of SC is defined in the grammar
file. The idea of the language is similar to C but there're a little important things to say:
5 / 2
is 2
and not 2.5
.nil
, 0
, ""
and false
are considered false, while any other value is considered true.and
and or
, instead of &&
and ||
. Also, it doesn't have type checking and doesn't guarantee that the result of a logical operation is a boolean value. For example, "hi" or false
is "hi"
.else
it's solved with the "nearest" if
statement (conventional in C-like languages).var
to re-define variables. Isn't a good practice, but it's allowed to do something like var x = 2; var x = 3;
.Now, the language is pretty simple but Turing-complete, so you can do anything with it. There aren't functions or classes yet, like there aren't another value types as arrays or objects.
Some features and things that will be nice to implement in the future are:
println
operator to have the possibility to print with a newline and allow print
to do without itx += 2
, x -= 3
, x *= 4
and x /= 5
.else if
statements to have a more readable syntax.x = (a > b) ? a : b
.do while
statement.