Warp is a modern, experimental compiler written in Rust. It features a clean architecture, modular design, and a simple language for learning and prototyping compiler concepts.
- Lexical analysis (tokenizer)
- Parsing to an Abstract Syntax Tree (AST)
- Semantic analysis (variable redefinition, undefined variable, and type checking)
- Type system:
int,float,bool,string,void - Functions with typed parameters and return types
- Type annotations for variables
- Type-checked function calls and assignments
- Pseudo-assembly code generation
- Command-line interface (CLI)
Warp supports a static type system with the following types:
int– 64-bit signed integerfloat– 64-bit floating pointbool– Boolean (trueorfalse)string– String literalsvoid– For functions that do not return a value
Type checking is enforced for all variable declarations, assignments, and function calls.
You can define functions with typed parameters and return types:
fn add(x: int, y: int) -> int {
return x + y;
}
fn is_positive(n: int) -> bool {
return n > 0;
}
fn greet(name: string) -> void {
// ...
}
Function calls are type-checked:
let result: int = add(2, 3);
let check: bool = is_positive(result);
You can annotate variables with types, or let the compiler infer the type:
let x: int = 42;
let y: float = 3.14;
let flag: bool = true;
let message: string = "Hello!";
let inferred = 100; // Type inferred as int
let x: int = 5;
let y: int = 10;
let z: int = x + y * 2;
let result: int = (x + y) * (z - 3) / 2;
if (x > 0) {
let y: int = x * 2;
} else {
let y: int = 0;
}
let i: int = 0;
while (i < 10) {
let square: int = i * i;
i = i + 1;
}
fn multiply(a: float, b: float) -> float {
return a * b;
}
let product: float = multiply(2.5, 4.0);
See example.warp for a complete example demonstrating all features.
- Fork the repository and create a feature branch.
- Write clear, concise commit messages.
- Add tests for new features.
- Open a pull request with a description of your changes.
MIT