Skip to content
All projects
SystemsCompleted

tinyc

A compiler for a small C-like language that generates x86-64 assembly, written in C++ for my compiler design course.

Programmer working at a desk with a dark-themed code editor on screen

Key results

  • Supports functions, recursion, pointers and arrays
  • Generates assembly that links against the standard C library
  • Matches GCC output on a 200-program test suite

Overview

tinyc compiles a subset of C, including functions, loops, pointers and arrays, into x86-64 assembly that runs on Linux. I built it to understand what really happens between source code and machine code.

  • Hand-written lexer and recursive-descent parser that produce an abstract syntax tree
  • Semantic analysis with scoped symbol tables and type checking
  • Code generation with a simple register allocator and stack frames that follow the System V ABI

A test harness compiles 200 sample programs with both tinyc and GCC and compares their output.