This project implements a fully functional Python-based interpreter for a simplified programming language. The interpreter processes source code by tokenizing input, building an Abstract Syntax Tree (AST), and executing the parsed instructions. It provides a hands-on understanding of core interpreter concepts, including lexical analysis, parsing, and AST-based execution.
The project is being developed as part of the CS 609: Final Project Assignment Southeast Missouri State University and adheres to the requirements outlined in the project guidelines.
-
Variable Assignments
- Supports declaring and initializing variables.
- Example:
let a = 5; let b = a + 3;
-
Arithmetic Operations
- Handles addition (
+
), subtraction (-
), multiplication (*
), and division (/
). - Example:
let c = a * b;
- Handles addition (
-
Output Printing
- Prints variable values using the
print
statement. - Example:
print(a); print(c);
- Prints variable values using the
-
Sequential Statements
- Parses and executes multiple statements in order.
- Example:
let x = 10; let y = x * 2; print(x); print(y);
-
Whitespace and Semicolon Handling
- Ignores whitespace and requires semicolons (
;
) to separate statements.
- Ignores whitespace and requires semicolons (
lexer.py
- Tokenizes the source code into meaningful symbols such as keywords, identifiers, numbers, and operators.
parser.py
- Builds an Abstract Syntax Tree (AST) from tokens to represent the program's hierarchical structure.
ast_nodes.py
- Defines classes for AST nodes, including
AssignNode
,BinOpNode
, andPrintNode
.
- Defines classes for AST nodes, including
interpreter.py
- Traverses the AST and executes operations such as variable assignments, arithmetic computations, and print commands.
examples/
- Contains sample programs and test cases demonstrating the interpreter’s functionality.
- Python 3.7 or higher.
- Clone this repository:
git clone https://github.com/parastiware/Interpreter.git cd interpreter
- Write a sample program in the input format, such as:
Save it in a file (e.g., program.txt).
let x = 10 + 5; let y = x * 2; print(x); print(y);
- Run the interpreter:
python main.py program.txt