Skip to content

tesso57/zig-cc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zig-cc

低レイヤを知りたい人のための 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)_)? ")"

参考 web サイト

zig の勉強

zig のリポジトリ

zig 公式リファレンス

c compiler emulator

メモ

zig で作成したオブジェクトファイルを c から呼び出す

$ zig build-obj src/foo.zig -fcompiler-rt
$ clang  -Wall -Wextra -std=c11 -pedantic -O3 -o main foo.o main.c

About

9ccのzig版

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published