A compiler for WLP4 (subset of C) that generates MIPS assembly code.
The compiler is organized into modular components with clean interfaces:
WLP4 Source Code
↓
[Scan] → Tokens
↓
[Parse] → Parse Tree
↓
[Type] → Typed Parse Tree
↓
[Gen] → MIPS Assembly
↓
[Asm] → Final MIPS Code
- scan.cc/h: Lexical analysis (tokenization)
- parse.cc/h: Syntax analysis (parsing)
- type.cc/h: Semantic analysis (type checking)
- gen.cc/h: Code generation (MIPS assembly)
- asm.cc/h: Assembler (MIPS code processing)
- main.cc: Main compiler driver
make clean
makeThis produces a single wlp4 executable.
./wlp4 < input.wlp4 > output.mipsOr compile from source:
cat my_program.wlp4 | ./wlp4 > my_program.mipsint wain(int a, int b) {
return a + b;
}Each module exports clean functions:
scanTokens(string)→ vectorbuildParseTree(tokens)→ ParseNode*typeCheck(parseTree)→ stringgenerateCode(typedTree)→ stringassemble(assembly)→ string
This modular design makes it easy to test individual stages and extend the compiler.
make cleanRemoves all build artifacts.