/gocc

a toy c compiler for m1 chip written in go.

Primary LanguageGoMIT LicenseMIT

CI Build Status

gocc

a toy c compiler for macOS(m1) written in go.
macOS向け9ccのc実装(未完成)のgo再実装

参考:

条件分岐に使用するeq,neなどの一覧

memo:

  • Zero Flag (Z)
  • Carry Flag (C)
  • Negative Flag (N)
  • Overflow Flag (V)

ebnf

program    = toplevel*
toplevel   = ident "(" (ident ","?)* ")" stmt
stmt       = expr ";"
           | "return" expr ";"
           | "if" "(" expr ")" stmt ("else" stmt)?
           | "while "(" expr ")" stmt
           | "for" "(" expr? ";" expr? ";" expr? ")" stmt
           | "{" stmt* "}"
expr       = assign
assign     = andor ("=" assign)?
andor      = equality ("&&" equality | "||" equality)*
equality   = relational ("==" relational | "!=" relational)*
relational = add ("<" add | "<=" add | ">" add | ">=" add)*
add        = mul ("+" mul | "-" mul)*
mul        = unary ("*" unary | "/" unary)*
unary      = ("+" | "-")? primary
primary    = num
           | ident ("(" (expr ","?)* ")")?
           | "(" expr ")"
           | """ ascii* """
ascii      = (0x21 - 0x7E)