This is a study project created for the "Compiler Construction" course at Radboud University Nijmegen. The project includes the complete compiler of the "Simple Programming Language" code to the "Simple Stack Machine" assembly.
The compiler has the code processing stages, including:
- Lexical analysis (lexer and parser),
- Semantic analysis (binding time analysis, polymorphism resolving, overloaded functions detection, and polymorphic type checking)
- Code generation (conversion of the AST into the SSM assembly, including the automatic garbage collection using reference counting)
The project requires Java version 25.
There are a few different ways a user can obtain the jar file to execute the project:
- The latest stable version of the project is available in the Releases section of the repository
- The user can build the executable jar from sources by using
gradlew
After obtaining the executable jar, the user can just run the following command:
java -jar build/libs/SPLCompiler-1.0-SNAPSHOT.jar
To run the project, the user needs to specify the path to the SPL source file as a first argument and the output path for the SSM assembly as the second argument:
java -jar build/libs/SPLCompiler-1.0-SNAPSHOT.jar test_programs/demos/game_of_life.spl out.ssm
There exist multiple compiler options:
| Option | Description |
|
|
This option enables the Automatic Reference Counting garbage collection assembly injections. |
|
|
This option runs the compiler in verbatim mode and shows the code transformations during the intermediate compilation stages. |
One can execute the generated assembly using the Simple Stack Machine interpreter:
java -jar ssm.jar --file out.ssm --cli
$ java -jar build/libs/SPLCompiler-1.0-SNAPSHOT.jar test_programs/demos/game_of_life.spl out.ssm
$ java -jar ssm.jar --file out.ssm --cli
+-----+
|.*...|
|..*..|
|***..|
|.....|
|.....|
+-----+
01234
+-----+
|.....|
|*.*..|
|.**..|
|.*...|
|.....|
+-----+
01234
+-----+
|.....|
|..*..|
|*.*..|
|.**..|
|.....|
+-----+
01234