Atul's Mini-C Compiler

June 2, 2004

Download the tarball.

This is a compiler for a subset of the C programming language. It was written in Python during the spring of 2004.

The lexer and parser were constructed using Dave Beazley's PLY (Python Lex-Yacc), an open-source Python implementation of GNU lex/yacc. Stages of compilation (symbol tree generation, type checking, flow control checking, etc) are performed using an object-oriented design pattern called a visitor (GoF 1995). The output is annotated Intel 80x86 assembly, suitable for translation to machine language using the GNU Assembler (GAS).

Language Features

The subset of the C language implemented here includes:

What went right What went wrong Examples

foo.c - Example C source file that uses most of the language features of the compiler.

foo.ast - Printout of the compiler's abstract syntax tree for foo.c after all passes of compilation have been completed.

foo.s - Annotated x86 assembly output of foo.c.

Other Notes

This software has been tested using Python 2.2 and Python 2.3 under Windows and Linux.