低レイヤを知りたい人のためのCコンパイラ作成入門の演習用リポジトリ
- ※ Linux/x86-64 でのみ動きます
- ※ vscode を使う場合は拡張機能 "Remote - Containers" で開発環境を整えられます
- chibicc
- branch: historical/old 最初こっちのブランチ見ながら書いてました
- branch: reference 途中からこっちのブランチ見るようになりました。
- std - Rust
program = (global-var | function)*
global-var = basetype ident ("[" num "]")* ";"
function = basetype ident "(" params? ")" "{" stmt* "}"
params = param ("," param)*
param = basetype ident ("[" num "]")*
stmt = "return" expr ";"
| "{" stmt* "}"
| "if" "(" expr ")" stmt ("else" stmt)?
| "while" "(" expr ")" stmt
| "for" "(" expr? ";" expr? ";" expr? ")" stmt
| declaretion
| expr ";"
declaretion = basetype ident ("[" num "]")* ("=" expr)? ";"
expr = assign
assign = equality ("=" assign)?
equality = relational ("==" relational | "!=" relational)*
relational = add ("<" add | "<=" add | ">" add | ">=" add)*
add = mul ("+" mul | "-" mul)*
mul = unary ("*" unary | "/" unary)*
unary = ("+" | "-")? primary
| ("*" | "&") unary
| postfix
postfix = primary ("[" expr "]")*
primary = num
| str
| "sizeof" unary
| funcall
| "(" expr ")"
funcall = ident ("(" (assign ("," assign)*)? ")")?
basetype = ("char" | "int") "*"*