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

https://github.com/tamaroning/ironcc

a toy C compiler written in Rust (llvm_sys) [new]
https://github.com/tamaroning/ironcc

c-compiler compiler llvm

Last synced: 12 months ago
JSON representation

a toy C compiler written in Rust (llvm_sys) [new]

Awesome Lists containing this project

README

          

# ironcc
A toy C compiler written in Rust which uses LLVM as backend.
ironcc is aiming to suppport C99, and C11.

# Install
```sh
$ git clone https://github.com/tamaroning/ironcc.git
$ cd ironcc
$ cargo build
```

# Usage
```sh
$ ironcc
```

To show the usage and version, run:
```sh
$ ironcc
```

# Status
ironcc supports the following functions:

- function definition
- local variable declaration
- return statement
- assignment
- types (int and pointer)
- control syntax (if, else, for)
- numerical literal
- binary operations (+, -, *, /)
- comparison operations (==, !=, <, >, <=, >=)
- unary operations (+, -)

# Syntax
```
program = top-level*

top-level = func-def

func-def = declspec declarator "{" compound-stmt

stmt = "return" expr ";"
| "if" "(" expr ")" stmt ("else" stmt)?
| "for" "(" expr-stmt expr? ";" expr? ")" stmt
| "while" "(" expr ")" stmt
| "{" compound-stmt
| expr-stmt

compound-stmt = (declaration | stmt)* "}"

declaration = declspec (declarator ("=" expr)? ("," declarator ("=" expr)?)*)? ";"

declspec = "int"

declarator = "*"* type-suffix

type-suffix = "(" func-params
|"[" "]"
| ε

func-params = (param ("," param)*)? ")"

param = declspec declarator

type-suffix = "(" func-params no
| "[" "]" type-suffix
| ε

expr-stmt = expr? ";"

expr = assign

assign = equality ("=" assign)?

equality = relational ("=="|"!=" relational)*

relational = add (("<"|">"|"<="|">=") add)*

add = mul (("+"|"-") mul)*

mul = unary (("*"|"/") unary)*

unary = ("+" | "-" | "*" | "&") unary
| postfix

postfix = primary ("[" expr "]")*

primary = "(" expr ")"
| "sizeof" unary
| func-args?
|

func-call = "(" (assign ("," assign)*)? ")"

means token.
```

# Todo
- support arithmetic operations of pointers
- support multi-[] operator (like a[3][4], b[0][1][3])