Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 1016 Bytes

README.md

File metadata and controls

38 lines (28 loc) · 1016 Bytes

C Compiler in Rust

Description

A Rust implementation of a simple C static program along the lines of:

int main(void) {
    return 2;
}

The compilation consists of three stages:

  1. The lexer: tokenizes the program.
  2. The parser: builds AST (as enums) and handles the proper syntax (as well as descending recursion that practically doesn't exist here because of simplicity)
  3. The assembly generator: outputs the assembly

Preprocessor and linker that were used are from gcc.

Project structure

/src
├── args.rs
├── compiler
│   ├── assembly_generator.rs
│   ├── lexer.rs
│   ├── mod.rs
│   └── parser.rs
└── main.rs

Reference

  1. Nora Sandler - Blog
  2. Writing C compiler
  3. Probably the best Stack post ever