An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

![Crust](https://github.com/almontasser/crust/assets/19656179/6ac3df79-264b-464b-a180-11d1870445c8)

# 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;
}
```