https://github.com/almontasser/crust
A C-like programming language that is similar to Rust's syntax. Toy programming language.
https://github.com/almontasser/crust
c compiler programming-language rust
Last synced: about 1 month ago
JSON representation
A C-like programming language that is similar to Rust's syntax. Toy programming language.
- Host: GitHub
- URL: https://github.com/almontasser/crust
- Owner: almontasser
- Created: 2023-12-15T19:22:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-11-28T22:32:57.000Z (4 months ago)
- Last Synced: 2025-11-30T21:25:13.324Z (4 months ago)
- Topics: c, compiler, programming-language, rust
- Language: Rust
- Homepage:
- Size: 322 KB
- Stars: 56
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# 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
- [x] Global Variables
- [x] Functions
- [x] Arrays
- [x] Integers (signed and unsigned)
- [x] Strings
- [x] Binary Operations
- [x] Code Generation (GNU Assembly)
- [x] Print to Console (integers & ascii characters)
- [x] If Statements
- [x] While Statements
- [x] For Statements
- [x] Function Parameters
- [x] Function Arguments
- [x] Local Variables (Scopes)
- [x] 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
```sh
cargo run # 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
```sh
./runtests.sh
```
If you're on macOS or another non-Linux system, you can run the tests in a
Linux Docker container using the provided `Dockerfile`:
```sh
./docker_runtests.sh
```
## Examples
Some examples of the language
```rust
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;
}
```
```rust
let a: u8;
let b: u8[25];
fn main(): u32 {
b[3]= 12; a= b[3];
printint(a);
return 0;
}
```