This repository contains a compiler written in Rust for a simple programming language (SPP).
To use this compiler, you need:
- Rust compiler (
rustc) and Cargo
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh- NASM (Netwide Assembler)
- ld (GNU Linker)
cargo buildcargo run examples/sample.sppnasm -f elf64 build/out.asm -o build/out.o && \
ld -m elf_x86_64 -o build/out build/out.o && \
./build/outCurrently, the SPP language supports:
- Single line comments (//)
- Multi line comments (/* */)
- Integers
- Floating-point numbers
- String literals (With both single- and double quotes)
- Booleans (true/false)
- Arrays (mixed types supported)
- Null values
- Constant declarations with compile-time evaluation
- Constants of any supported data type
- Complex expressions in constant initialization
- Constants can reference other constants
- Arithmetic operations (+, -, *, /)
- Comparison operations (==, !=, <, >, <=, >=)
- String concatenation
- Mixed-type operations (e.g., adding strings and numbers)
- If statements with condition evaluation
- Supports both simple and complex conditions
elseclauses for alternative execution paths- Nested
ifstatements for complex logic - Variable assignments inside conditional blocks
- Program termination:
exit(code);
- Console output:
console.print("Text"); - String interpolation:
console.print("Value: " + variable);
- Generates x86_64 NASM assembly
- Optimized constant handling
- Proper memory management
const username = "Stiwyy";
const currentDate = "2025-08-14";
const currentTime = "23:53:15";
console.print("SPP Demo");
console.print("User: " + username);
console.print("Date: " + currentDate + " " + currentTime);
const pi = 3.14159;
const radius = 5;
const area = pi * radius * radius;
console.print("Circle area: " + area);
// If statement example
let temperature = 22;
if (temperature > 25) {
console.print("It's warm today!");
} else {
console.print("It's a cool day.");
}
// Nested if example
let hour = 14;
if (hour < 12) {
console.print("Good morning!");
} else {
if (hour < 18) {
console.print("Good afternoon!");
} else {
console.print("Good evening!");
}
}
exit(0);
src/lexer.rs: Tokenizes the source codesrc/parser.rs: Parses tokens into an ASTsrc/ast.rs: Definitions for the abstract syntax treesrc/codegen.rs: Generates NASM assembly codesrc/main.rs: Main program that connects all components