This repository contains a small interpreter written in C++ with a syntax inspired by Python. It is an educational project to learn about lexical analysis (lexer), parsing, AST (abstract syntax tree) nodes, and evaluation/interpretation.
interpreter/- core implementation:Lexer,Parser,Interpreter, ASTNodedefinitions,Token,Value, andFileutilities.main.cpp- C++ entry point.
- CMake (>= 3.10 recommended)
- A recent C++ compiler (Clang or GCC with C++11/14/17 support)
- (Optional) An IDE such as CLion or VSCode, or build tools like Make/Ninja
Open a terminal at the repository root and run:
mkdir -p build && cd build
cmake ..
cmake --build .To run the interpreter on Linux and MacOS:
cd build
./python_interpreter path/to/script.pyTo run the interpreter on Windows:
cd build
python_interpreter.exe path/to/script.py# example.py
x = 0
for i in range(5):
print(i)
print("End of loop")
Expected output (implementation-dependent):
0
1
2
3
4
End of loop
interpreter/Lexer.*- tokenizationinterpreter/Parser.*- AST constructioninterpreter/Interpreter.*- AST execution/evaluationinterpreter/Node/- AST node definitions (AssignNode, ForNode, PrintNode, etc.)interpreter/File.*- file reading utilities