A Rust implementation of a simple C static program along the lines of:
int main(void) {
return 2;
}
The compilation consists of three stages:
- The lexer: tokenizes the program.
- 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)
- The assembly generator: outputs the assembly
Preprocessor and linker that were used are from gcc
.
/src
├── args.rs
├── compiler
│ ├── assembly_generator.rs
│ ├── lexer.rs
│ ├── mod.rs
│ └── parser.rs
└── main.rs