Skip to content

ab0626/Warp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Warp Compiler

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.

Features

  • 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)

Type System

Warp supports a static type system with the following types:

  • int – 64-bit signed integer
  • float – 64-bit floating point
  • bool – Boolean (true or false)
  • string – String literals
  • void – For functions that do not return a value

Type checking is enforced for all variable declarations, assignments, and function calls.

Functions

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);

Variable Declarations and Type Annotations

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

Example Language Syntax

Variable Assignment

let x: int = 5;
let y: int = 10;
let z: int = x + y * 2;

Arithmetic Expressions

let result: int = (x + y) * (z - 3) / 2;

If Statement

if (x > 0) {
    let y: int = x * 2;
} else {
    let y: int = 0;
}

While Loop

let i: int = 0;
while (i < 10) {
    let square: int = i * i;
    i = i + 1;
}

Functions and Type Checking

fn multiply(a: float, b: float) -> float {
    return a * b;
}

let product: float = multiply(2.5, 4.0);

Example Source File

See example.warp for a complete example demonstrating all features.

Contribution Guidelines

  • 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.

License

MIT

About

Experimental compiler in Rust, and more coming: lexical analysis, AST parsing, semantic analysis, type system (int/float/bool/string), functions with typed parameters, and code generation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages