Skip to content
/ 9cc Public

C compiler based on the Rui Ueyama's Compiler Book

Notifications You must be signed in to change notification settings

ktateish/9cc

Repository files navigation

9cc - C compiler based on the Rui Ueyama's Compiler Book

9cc is a small, simple, easy to understand C compiler developed by Rui Ueyama. This repositry is my implementation of 9cc based on his book '低レイヤを知りたい人のためのCコンパイラ作成入門'.

TODO

Feature

  • Calculator-like language
    • Compile a single integer
    • Addition and Subtraction
    • Tokenizer
    • Multiplication and Division
    • Unary + and -
    • Comparison operators
    • Support arbitrary length input
  • Separated compilation
  • Variables and functions
    • Single character local variables
    • Support return statement
    • Multi-character local variables
    • Control structures
      • if
      • while
      • for
    • Block
    • Function call
    • Function definition
  • Pointer and string literal
    • Introduce 'int' keyword instead of implicit type declaration
    • Support pointer type
    • Pointer addition/subtraction
    • Support sizeof operator
    • Support array type
    • Index of array
    • Global variables
    • Support char * type
    • String literal
    • Input from file
    • Line comment and block comment
    • Rewrite tests in C
  • Executable image and initialization expression
  • Syntax of types in C

Refactoring

  • propagate 'input' to all node types
  • Rename type to kind
  • Separate files
  • Add rewriting AST rule for &array_name case.
  • Implement selectors for kind of Node and kind of Type of Node
  • Use 4-byte size for int
  • Implement functions for Type size

About

C compiler based on the Rui Ueyama's Compiler Book

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages