Skip to content

danielaloisio/python-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Python-like Interpreter (C++)

Description

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.

Project layout

  • interpreter/ - core implementation: Lexer, Parser, Interpreter, AST Node definitions, Token, Value, and File utilities.
  • main.cpp - C++ entry point.

Prerequisites

  • 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

How to build (macOS / Linux / Windows (MSYS2))

Open a terminal at the repository root and run:

mkdir -p build && cd build
cmake ..
cmake --build .

Running the interpreter

To run the interpreter on Linux and MacOS:

cd build
./python_interpreter path/to/script.py

To run the interpreter on Windows:

cd build
python_interpreter.exe path/to/script.py

Example script (example.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

Code structure

  • interpreter/Lexer.* - tokenization
  • interpreter/Parser.* - AST construction
  • interpreter/Interpreter.* - AST execution/evaluation
  • interpreter/Node/ - AST node definitions (AssignNode, ForNode, PrintNode, etc.)
  • interpreter/File.* - file reading utilities

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors