Skip to content

Latest commit

 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🪙 Copper Programming Language

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.


🔩 Core Components

  • 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 .cop source files directly for execution.

🗺️ Roadmap

✅ Completed

  • Lexer: Convert source text into tokens.
  • Parser: Build an AST from tokens.
  • Visitor (Evaluator): Execute AST nodes.
  • File input and execution support.

🚀 Upcoming Features

  • Arithmetic operations (+, -, *, /)
  • Control flow (if / else)
  • New data types (number, boolean, etc.)
  • Error handling and debugging improvements
  • REPL (interactive shell)

⚙️ Getting Started

1. Dependencies

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.


2. Building the Project

Clone the repository and navigate to the project folder:

git clone https://github.com/AmalSKumar0/copper.git
cd copper

Build using make:

make

This compiles all .c files, links them, and produces the copper.exe (or ./copper on Linux/macOS).


3. Running a Copper Program

To execute a Copper source file:

# Windows
.\copper.exe test.cop

# Linux / macOS
./copper test.cop

Example: test.cop

var name = "Hello World!";
print(name);

Expected Output:

Hello World!

🧰 Makefile Commands

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

4. Running a Copper Program After Installing

To execute a Copper source file:

# Windows
copper test.cop

Example: test.cop

var name = "Hello World!";
print(name);

Expected Output:

Hello World!

🧠 Learning Objective

This project is primarily an educational experiment — to explore:

  • Tokenization and lexical analysis
  • Recursive descent parsing
  • AST construction and traversal
  • Interpreter evaluation model

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages