This project aims to implement a compiler for a simplified version of the Turing programming language, which is not fully compatible.
It's split into 3 phases:
The required tools and build steps for each phase are described in detail in their corresponding README
s.
The common tools required across the phases include gcc
, as the sT compiler is written in C, as well as make
and cmake
, which generate the executables.
All tools required by the sT compiler are packed into containers, which you can use to build or develop the compiler.
Compile the phases of the sT compiler.
$ make
We may get a lot of warnings due to the legacy Javaa tool.
Then, you can run the sT program with the st.sh
script.
$ chmod +x st.sh
$ ./st.sh -h
Usage: ./st.sh [-h] FILE
Description:
runs the FILE, which is a sT program,
and outputs Java Assembly to .jasm and ByteCode to .class
Options:
-h, --help show this help message and exit
We provide a Docker image that contains only the necessary tools for compiling the sT compiler. "Non-Dev" indicates that the image doesn't include test tools, format tools, or other utilities.
The image can be built locally with the Dockerfile
.
$ docker build --tag st-lang .
Then, run a new container in interactive mode with a pseudo-TTY allocated. We've already specified the /bin/sh
command in the image, so you can omit the command argument.
$ docker run -it st-lang
Alternatively, use
docker run -it st-lang /bin/bash
to use the Bourne again shell (Bash) instead of the Bourne shell (sh).
You're now inside the container. You should see a hashtag (#
) waiting for your commands. Go play around!
The dev container contains all the tools you'll need during the development, such as ClangFormat, Clang-Tidy, and Valgrind.
The dev container works with VSCode. You'll need to install the Dev Containers extension.
After the installation, click the green status bar item at the far left and select Reopen in container
. This will start building the image and then run a container for you.
Note You'll need to click
Reopen in container
every time you want to enter the dev container. It will start the same container you previously ran.
You will then be taken into the container. Here you have all the tools you need, including some useful VSCode extensions. Enjoy your journey!
Learn more about Developing inside a Container.
The definition of incompatibility here is that the code using the syntax mentioned below compiled with the sT compiler but does not compiled with the tpc compiler.
syntax | sT | Turing |
---|---|---|
block comment | {% ... %} |
/* ... */ |
escaped quote | "" |
\" |
boolean datatype | bool |
boolean |
array subscript | arr[1] |
arr(1) |
substring | str[1 .. 2] |
str(1 .. 2) |
function | may have side effects | may NOT have side effects |
skip |
use solely to print a newline | use with get & put to detect eof & print newlines |
subprogram declaration & call | always parenthesis | no parenthesis when on parameter |
put bool_expr |
syntax error, unprintable | print "true" for true and "false" for false |
- The lexical definition of sT
- The syntactic & semantic definition of sT
- The Turing Language Report
- Unsupported features
The sT compiler is licensed under the MIT License.