top of page

C- Compiler

 
 

Purpose


This compiler processes a subset of C-like code with support for basic arithmetic, logical operations, variable declarations, arrays, and control flow statements (if, else). It compiles code into a sequence of intermediate steps, performing syntax analysis, lexical analysis, and symbol table management. The final result is runnable MIPS assembly code.


 

Key Features


Variable Declarations: Supports variable declaration for basic types such as int, char, bool, and float. Arrays are also supported.

Control Flow: Supports conditional execution using if and else, with compound conditions combining logical (&&, ||, !) and comparison operators (<, >, <=, >=, ==, !=).

Arithmetic: Basic arithmetic operations (+, -, *, /) with order of operations are supported.

Write Functions: The write() and writeln() functions are used to output values to the console.

Symbol Table: Maintains a symbol table for tracking declared variables and functions, ensuring that types and values are validated correctly. Includes support for scoping (global and function-level).

Boolean Validation: Ensures that bool variables are assigned only valid values ("1" or "0").

Optimizations: Implements optimizations such as constant folding and dead code elimination to improve efficiency by reducing redundant calculations and simplifying expressions at compile time.


 

Challenges & Solutions


One of the challenges was managing MIPS code generation, especially separating labels and variables from the main code. To solve this, I created separate files for each during the compilation process, then merged them into the final MIPS assembly output.

(For a more detailed explanation with source code, check out the video linked below.)


 

Outcome


The C- Compiler successfully translates source code into optimized MIPS assembly, demonstrating my ability to design and implement a full compilation pipeline. The project highlights my understanding of compiler construction and my ability to apply optimizations to produce efficient, executable machine-level code.



 


bottom of page