Skip to content

A C-like programming language that is similar to Rust's syntax. Toy programming language.

Notifications You must be signed in to change notification settings

almontasser/crust

Repository files navigation

Crust

CRUST

This is a hobby project to learn about compilers and language design. I've designed the language to be similar to C and Rust.

Heavily inspired by https://github.com/DoctorWkt/acwj

Features

  • Global Variables
  • Functions
  • Arrays
  • Integers (signed and unsigned)
  • Strings
  • Binary Operations
  • Code Generation (GNU Assembly)
  • Print to Console (integers & ascii characters)
  • If Statements
  • While Statements
  • For Statements
  • Function Parameters
  • Function Arguments
  • Local Variables (Scopes)
  • Function Hoisting
  • Reading from console
  • Dynamic Arrays
  • Structs
  • Unions
  • Enums
  • Break & Continue
  • Variable Initialization
  • Casting
  • Sizeof
  • Static
  • Struct Methods
  • Struct Traits
  • LLVM

How to use

cargo run <input-file> # Compile the crust language to assembly, which will be written to out.s
cc -no-pie -z noexecstack -o bin out.s # Use the GNU C compiler to compile and link the assembly code to an executable file
./bin # Execute the produced binary

Run tests

./runtests.sh

Examples

Some examples of the language

let c: char;
let str: *char;

fn main(): u8 {
  c= '\n'; printint(c);

  for (str= "Hello world\n"; *str != 0; str= str + 1) {
    printchar(*str);
  }
  return 0;
}
let a: u8;
let b: u8[25];

fn main(): u32 {
  b[3]= 12; a= b[3];
  printint(a);
  return 0;
}

About

A C-like programming language that is similar to Rust's syntax. Toy programming language.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published