TesLang is a custom programming language designed for educational purposes. This project includes the front-end compiler for TesLang, developed using Python and PLY (Python Lex-Yacc).
TesLang is a custom language designed to help users understand the basics of compiler construction. It includes a lexer, parser, semantic analyzer, and intermediate representation (IR) generator. This project demonstrates the front-end compilation process, turning source code into an intermediate representation.
- Lexer: Tokenizes the input source code.
- Parser: Generates an abstract syntax tree (AST) from the tokenized input.
- Semantic Analyzer: Performs type checking and scope management.
- Intermediate Representation (IR) Generator: Converts the AST into an intermediate representation for further processing.
-
Clone the repository:
https://github.com/MortezaPr/Teslang.git cd Teslang
-
Install the required packages:
pip install -r requirements.txt
To compile a TesLang source file, use the main.py
script. Ensure you have a TesLang source file named teslang_source.txt
in the same directory as main.py
.
python main.py
Tokenizes the input source code using PLY (Python Lex-Yacc).
Defines the tokens and reserved words used in the language.
Parses the tokenized input to generate an abstract syntax tree (AST).
Performs type checking and manages the symbol table.
Defines the AST node classes used by the parser and semantic analyzer.
Defines the IR node classes used by the IR generator.
Generates the intermediate representation from the AST.
Manages the symbols and their attributes during semantic analysis.
The entry point for the compiler, which ties together the lexer, parser, semantic analyzer, and IR generator.
Create a TesLang source file named teslang_source.txt
with the following content:
fn add(a as int, b as int) <int>
{
result :: int = a + b;
return result;
}
Run the compiler using the following command:
python main.py
Contributions are welcome! Please fork the repository and submit pull requests.
- Fork the Project
- Create your Feature Branch (git checkout -b feature/AmazingFeature)
- Commit your Changes (git commit -m 'Add some AmazingFeature')
- Push to the Branch (git push origin feature/AmazingFeature)
- Open a Pull Request
Distributed under the MIT License. See the LICENSE file for more information.