This project implements a complete interpreter for the Trivial programming language, enhanced with a structured for loop construct. The project demonstrates a standard compiler pipeline, including lexical analysis, recursive-descent parsing, and status-aware evaluation.
- Expressions: Arithmetic, comparison, and logical operators with correct precedence.
- Statements: Variable assignment,
printstatements, and block structures. - Control Flow:
if/else,whileloops, and the newly addedforloop. - Functions: First-class functions with lexical scoping and parameter binding.
- Status Handling: Support for
return,break,continue, andexitvia status-aware evaluation. - Syntactic Sugar: The
forloop is implemented by desugaring it into awhileloop at the parser level.
tokenizer.py: Uses Regular Expressions to convert source code into tokensparser.py: Implements a recursive-descent parser that generates an Abstract Syntax Tree (AST).evaluator.py: Traverses the AST and executes the program logic using environments.runner.py: The main entry point to execute.tsource files.
- Ensure you have Python 3.x installed.
- Place your source code in a file with a
.textension (e.g.,example.t). - Run the interpreter using:
python3 runner.py example.t