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]
- Host: GitHub
- URL: https://github.com/tamaroning/ironcc
- Owner: tamaroning
- License: mit
- Created: 2021-09-22T02:55:05.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-09T07:35:55.000Z (over 4 years ago)
- Last Synced: 2025-02-14T11:35:10.096Z (about 1 year ago)
- Topics: c-compiler, compiler, llvm
- Language: Rust
- Homepage:
- Size: 113 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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])