低レイヤを知りたい人のための C コンパイラ作成入門 を zig で実装する リポジトリ
program = stmt*
stmt = expr ";"
| "if" "(" expr ")" stmt ("else" stmt)?
| "while" "(" expr ")" stmt
| "for" "(" expr? ";" expr? ";" expr? ")" stmt
| "{" stmt* "}"
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
primary = num | ident | "(" expr ")" | funcall
funcall = ident "(" (assign, ("," assign)_)? ")"
- https://github.com/ziglang/zig
- コンパイラそのものなので、参考になる気がする。
$ zig build-obj src/foo.zig -fcompiler-rt
$ clang -Wall -Wextra -std=c11 -pedantic -O3 -o main foo.o main.c