Skip to content

kzok/exercise-c-compiler

Repository files navigation

C コンパイラ演習

CircleCI

低レイヤを知りたい人のためのCコンパイラ作成入門の演習用リポジトリ

  • ※ Linux/x86-64 でのみ動きます
  • ※ vscode を使う場合は拡張機能 "Remote - Containers" で開発環境を整えられます

参考資料

文法

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") "*"*

About

C コンパイラ演習

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published