Interpreter for Tempest language - a statically typed language based on latte lang.
You can build the interpreter using make command. This will create an executable interpreter, which can run in two modes:
- reading from stdin,
- reading from a file.
make
./interpreter OR ./interpreter <program_name>.tms.
#reading from stdin OR reading from a file
Reading from stdin can be terminated using ctrl+D.
All Tempest specifications can be found inside lang folder. Grammar is located in the Tempest.cf file and is written using LBNF notation. More detailed description of the language can be found in TempestDesc.pdf (polish only).
Interpreter analyzes passed code in three phases:
- Syntax check and tokenizing
- Checks whether the code can be generated using grammar from Tempest.cf file.
- Converts the string into a tree of non-terminal symbols.
- Possible non-terminals are located inside AbsTempest.hs file.
- This part is mostly done by autogenerated files based on a given grammar. Files that operate in this phase are located in src/Syntax folder.
- Typechecker
- This phase is responsible for correct static typing of program.
- Typechecker analyzes a given program, throwing an exception to stderr if it has any errors.
- All possible exception types can be found in TypecheckerData.hs file.
- All files of this part are located inside src/Typecheck folder.
- Interpreter
- Main phase of the whole project, which evaluates the given program.
- Interpreter may throw runtime exceptions, such as division by zero or no return encountered exceptions.
- Files regarding this part are stationed in src/Interpret folder.
Tempest has four build-in functions:
- error(), which throws an error called runtime exception, effectively stopping the program from further execution,
- printInt(i), which prints a given integer to stdin,
- printBool(i), which prints a given bool to stdin,
- printString(i), which prints a given string to stdin (note that you can concatenate strings using +++ sign).
All programs must start somewhere, and in case of Tempest they all should start in a zero argument procedure called main. Programs may contain comments - every character after a '//' symbol is ignored by the interpreter. If you opt for a multi-line text you can use a '/*' symbol to begin and '*/' to end a comment.
You can find both good and bad examples inside examples folder. Good examples show all possible functionalities of Tempest language, while bad examples show all possible syntax, typecheck and runtime exceptions.