Building MT22, a C-like language
MT22 is a C-like language. It is similar enough to C to feel familiar, but different enough to give you some sense of alternatives.
This is my Principle of Programming Language's assignment. In this assignment, I was asked to build a C-like programming language (MT22) from scratch. The assignment is divided into 4 phases:
- Lexer and Parser: Teach your language how to identify tokens and lexemes
- Input: program.
- Output: Parse tree
- File modified: src/main/mt22/parser/MT22.g4
- AST generation: Build AST tree from Parse tree (omit some non-relevant symbols in parse tree)
- Input: Parse tree
- Output: AST tree
- File modified: src/main/mt22/astgen/ASTGeneration.py
- Checker: Doing static check and throw error when needed
- Input: AST tree
- Output: None if program have no errors in static check else throw errors
- File modified: src/main/mt22/checker/StaticChecker.py
- Code Generation: Run and generate code (values, results) from AST tree (Not yet)
- Input: AST tree
- Output: N/A
- File modified: N/A
This repository includes phase 1 to phase 3.
This is an instruction of how to run this language on your local machine. In order to be able to use run antlr files, you need to do there things
- Java 19.0.2
- Python 3.11.2 (Current newest version)
- Antlr 4.9.2
After have installed all the necessary stuffs. Do following description in Specification_Instruction/README.txt
Set environment variable ANTLR_JAR to the file antlr-4.9.2-complete.jar in your computer
Change current directory to initial/src where there is file run.py
Type:
python run.py gen
You can then type (omit the part in parentheses):
python run.py test LexerSuite (test your Lexer code)
python run.py test ParserSuite (test your Parser code)
python run.py test ASTGenSuite (test your AST Gen code)
python run.py test CheckerSuite (test your Static Checker code)
python run.py test CodeGenSuite (test your Code Gen code)
These commands will run test files I have already built in HCMUT_PPL_Sem222_MT22/src/test/.
The testcases will then be exported to files in folder testcases while the solutions your code gives back will be exported to folder solutions. In order to make your own testcase, you just need to modify one of .py files in test folder.
In every test files, I have already included 100 testcases each. Feel free to use to test your system (No 100% guarantee though)
One example of how to test your code using src/test/CheckerSuiteone.py. This will do 1 testcase for your system, you just need to modify 2 parts in this file:
- Input: your AST tree or source functions (Checker will receive both formats)
- Expect: None or the error your static checker will throw out (your expected result)
Type
python run.py test CheckerSuiteone
in your cmd to run the testcase.
Distributed under the GNU License. See LICENSE.txt
for more information.
Oanh Tran - oanh.tranotsc1123@hcmut.edu.vn
Project Link: https://github.com/Oztobuzz/HCMUT_PPL_Sem222_MT22.git