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

Overview

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;
}
You might also like...
Rmt - similar to the rm command, but it allows me to save the deleted elements in the trash
Rmt - similar to the rm command, but it allows me to save the deleted elements in the trash

Rmt is similar to the rm command but saves the deleted elements in the trash and restores them. Rmt is written in Rust 🦀

An over-simplified version control system written in Rust, similar to Git, for local files (Incomplete)

Vault Vault will be a command line tool (if successful) similar to git which would have multiple features like brances etc etc. __ __ _ _

A bit like tee, a bit like script, but all with a fake tty. Lets you remote control and watch a process

teetty teetty is a wrapper binary to execute a command in a pty while providing remote control facilities. This allows logging the stdout of a process

Turbine is a toy CLI app for converting Rails schema declarations into equivalent type declarations in other languages.

Turbine Turbine is a toy CLI app for converting Rails schema declarations into equivalent type declarations in other languages. It’s described as a to

a (soon to be) calculator frontend and a (soon to be optimizing) toy IR backend

Zach-Calc Zach-Calc is a pet project for me to try and better understand pattern matching, optimization, IRs, and the likes. ./libs/* contains librari

A toy-clone of ping

Rong Ping is a simple command that is used to check the liveness of a server. Ping measures the round-trip time for messages sent from the originating

A toy example showing how to run Rust code in Python for speed and progress.

PoC: Integrating Rust in Python A toy example showing how to run Rust code in Python for speed and progress. Requirements Python 3.6+ Rust 1.44+ Cargo

Toy Shell Written in Rust
Toy Shell Written in Rust

This is a simple toy shell written in Rust language with porpose of learning system programmim, and in a specific theme, process management.

For something between the likes of a toy bootloader or tiny kernel and Arch Linux.

For something between the likes of a toy bootloader or tiny kernel and Arch Linux.

Comments
  • Linking example assembly fails when using PIE

    Linking example assembly fails when using PIE

    Great work on this repo, it's quite motivating to see local devs taking on such cool and challenging projects, would love to contribute some day if I get the chance to

    According to the README file, it is mentioned that the command cc -o bin out.s can be used to link the assembly to a binary, but it always fails without passing the -no-pie flag (at least in my env)

    Maybe consider adding it in the docs to avoid confusion?

    opened by ibrahimelaradi 1
Owner
Mahmoud Almontasser
Backend developer, Network admin, DevOps admin. Database admin.
Mahmoud Almontasser
Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. A tokei/scc/cloc alternative.

tcount (pronounced "tee-count") Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. Quick Start Simply run tcount

Adam P. Regasz-Rethy 48 Dec 7, 2022
A prolog like syntax for egg

egglog Using the egg library with a file format and semantics similar to datalog. Explanatory blog posts: https://www.philipzucker.com/egglog-checkpoi

Philip Zucker 40 Dec 1, 2022
Valq - macros for querying and extracting value from structured data by JavaScript-like syntax

valq   valq provides a macro for querying and extracting value from structured data in very concise manner, like the JavaScript syntax. Look & Feel: u

Takumi Fujiwara 24 Dec 21, 2022
A simple, C-like, ternary operator for cleaner syntax.

A simple ternary operator macro in rust. the iff! macro is the only item exported by this crate, it simply takes three expressions, seperated by ? and

KaitlynEthylia 42 May 23, 2023
Rust Server Components. JSX-like syntax and async out of the box.

RSCx - Rust Server Components RSCx is a server-side HTML rendering engine library with a neat developer experience and great performance. Features: al

Antonio Pitasi 21 Sep 19, 2023
Notes on learning the Rust programming language syntax.

notes-on-rust Notes on learning the Rust programming language syntax. Resources https://www.rust-lang.org/learn/get-started https://doc.rust-lang.org/

Fred Snyder 1 Jan 2, 2022
*slaps roof of [programming language]* this bad boy can fit so much [syntax sugar] into it

An attempt to give myself a new Pareto-optimal choice for quick-and-dirty scripts, particularly when I'm not on a dev computer, and to practice writin

Brian Chen 985 Apr 25, 2023
A BASIC language interpreter. Does not conform to existing standards. Mostly a toy.

JW-Basic A toy language that is somewhat like QBasic. Features: Graphics: 160x96 (255 colors & transparent) Text: 32x16 (4x5 font) Character set: ASCI

John Wells 8 Feb 15, 2023
Rmatrix is similar to the cmatrix, but it wrote it in Rust.

Rmatrix is similar to the cmatrix, but it wrote it in Rust. Get up to 75% performance improvement compared to cmatrix.

null 8 Apr 8, 2022
koyo is a cli tool that lets you run commands as another user. It is similar to doas or sudo.

koyo is a cli tool that lets you run commands as another user. It is similar to doas or sudo.

null 3 Nov 27, 2021