Pseudo CPP Interpreter

30 Apr 2023 • 2 min read

Pseudo C++ Interpreter (Bash)

Pseudo-C++ Interpreter is a Bash-based interactive interpreter that simulates a basic C++ REPL-like experience in the terminal.

It allows users to write and execute C++ statements line by line without manually creating a full C++ program. Internally, the script dynamically wraps user input into a valid C++ source file, compiles it using G++, and executes the binary.

This project demonstrates process automation, shell scripting, and dynamic code generation.

How It Works

  • User inputs C++ statements interactively
  • Each statement is appended to a temporary buffer
  • The script automatically generates a complete C++ program:
    • Adds headers
    • Wraps input inside main()
  • Compiles the code using g++
  • Executes the compiled binary
  • Invalid or problematic statements are commented out automatically
This is not a full C++ interpreter — it relies on runtime compilation.

Supported Commands

CommandDescription
helpDisplay available commands
clearClear the terminal screen
resetReset current code buffer
exitExit interpreter and cleanup
cpp <file>Compile & execute a C++ file
coutSupported (auto-commented after execution)
cinNot supported

Requirements

  • Linux / macOS (or WSL)
  • Bash shell
  • G++ compiler

Verify installation:

BASH
g++ --version

Usage

  1. Clone the Repository
    BASH
    git clone https://github.com/patkarmandar/Pseudo-CPP-Interpreter.git
    cd Pseudo-CPP-Interpreter
  2. Make Script Executable
    BASH
    chmod +x interpreter.sh
  3. Run the Interpreter
    BASH
    ./interpreter.sh
  4. Example Session
    CPP
    >> cout << "Hello World";
    Hello World
    >> int a = 5;
    >> cout << a;
    5

Limitations

  • cin input is not supported
  • Each command triggers recompilation
  • Not suitable for large programs
  • Intended for learning and experimentation

Future

  • Real REPL behavior
  • Syntax validation before compile
  • cin support via input buffering
  • Unit tests for interpreter logic

Start searching

Enter keywords to search articles.