Skip to content

C-Compiler built as part of my Year 2 coursework at Imperial and refined over Summer 2024

Notifications You must be signed in to change notification settings

SamuelKhoo2003/Fanta-C-Compiler

Repository files navigation

Fanta-C-Compiler

The Fanta-C-Compiler is a full-featured C-Compiler developed as part of my Year 2 coursework at Imperial College, with significant refinements made over the Summer of 2024.

Project Overview

  • Completion Date: March/April 2024
  • Scope: Engineered a comprehensive C-Compiler from scratch, encompassing the entire compilation pipeline within a Dockerized environment.
  • Key Achievements:
    • 100% Pass Rate: Successfully passed all standard and custom test cases.
    • Core C Features: Supported key C language features, including pointers, arrays, and various data types.
    • Advanced Optimizations: Implemented optimizations such as register allocation and dead code elimination for efficient memory management and precise type checking.

Features

Compilation Pipeline
  • Lexical Analysis: Tokenizes C source code into meaningful symbols.
  • Syntax Analysis: Builds an abstract syntax tree (AST) from tokens.
  • Semantic Analysis: Ensures type correctness and resolves symbols.
  • Optimization: Includes optimizations like dead code elimination and register allocation.
  • Code Generation: Outputs assembly code for a target architecture.
Core Language Features
  • Data Types: Supports all standard C data types including integers, floats, and pointers.
  • Control Structures: Implements if-else, loops, and switch statements.
  • Memory Management: Efficient handling of pointers and arrays.
  • Function Calls: Supports both recursive and non-recursive functions.
Advanced Optimizations
  • Register Allocation: Allocates CPU registers efficiently to minimize memory access.
  • Dead Code Elimination (In Progress): Removes code that does not affect the program's output.
  • Loop Unrolling (Planned): Expands loops to reduce the overhead of control structures.

Technologies Used

  • Programming Language: C++, Python, Assembly
  • Tools: Docker for containerization, GCC for testing, custom scripts for automation
  • Testing: Over 100 custom test cases alongside standard test suites

Installation and Setup

Setup Instructions
  1. Clone the repository:
    git clone https://github.com/SamuelKhoo2003/fanta-c-compiler.git
  2. Navigate to the project directory:
    cd fanta-c-compiler
  3. Build the Docker container:
    docker build -t fanta-c-compiler .
  4. Run the compiler within Docker:
    docker run -v $(pwd)/src:/app/src fanta-c-compiler

Important Note

This project was created as part of my coursework and is intended for educational purposes only. Please do not directly copy this work. Use it as inspiration or reference, but make sure to develop your own understanding and code.

About

C-Compiler built as part of my Year 2 coursework at Imperial and refined over Summer 2024

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published