Copper is a simple, interpreted programming language built entirely in C — designed as a personal project to understand the core principles of compiler and interpreter design, from lexing and parsing to AST evaluation.
This project represents a deep dive into how programming languages actually work under the hood.
🚧 Project Status: In Progress
Core interpreter components are now functional.
- Lexer – Reads raw source code and converts it into a stream of tokens.
- Parser – Takes the token stream and constructs an Abstract Syntax Tree (AST).
- AST – A structured, tree-based representation of the program’s logic.
- Visitor (Interpreter) – Walks the AST and executes the code (currently supports variable assignment and a
print()function). - File I/O – Reads
.copsource files directly for execution.
- Lexer: Convert source text into tokens.
- Parser: Build an AST from tokens.
- Visitor (Evaluator): Execute AST nodes.
- File input and execution support.
- Arithmetic operations (
+,-,*,/) - Control flow (
if/else) - New data types (
number,boolean, etc.) - Error handling and debugging improvements
- REPL (interactive shell)
To build and run Copper, you’ll need:
- A C compiler (e.g.,
gcc) make
Windows Users:
Install MSYS2 — it includes gcc, make, and a UNIX-like shell environment.
Clone the repository and navigate to the project folder:
git clone https://github.com/AmalSKumar0/copper.git
cd copperBuild using make:
makeThis compiles all .c files, links them, and produces the copper.exe (or ./copper on Linux/macOS).
To execute a Copper source file:
# Windows
.\copper.exe test.cop
# Linux / macOS
./copper test.copvar name = "Hello World!";
print(name);
Expected Output:
Hello World!
| Command | Description |
|---|---|
make |
Build the copper executable |
make install |
(Windows) Copies copper.exe to C:/tools — add this folder to your PATH |
make clean |
Removes the compiled executable and object files |
To execute a Copper source file:
# Windows
copper test.copvar name = "Hello World!";
print(name);
Expected Output:
Hello World!
This project is primarily an educational experiment — to explore:
- Tokenization and lexical analysis
- Recursive descent parsing
- AST construction and traversal
- Interpreter evaluation model