Building a C Compiler
This is the process of how I built a compiler in C. I will take you through the steps of breaking down a language and what goes on during the compilation process.
Overview
This was the final project that I created for my compiler class. The compiler that I built was written in the C language and converts a subset of the C language, Baby C, to an intermediary assembly language known as ILOC. It works by taking input from a file, then uses a software called FLEX to scan the file. After this I generate an LR(1) grammar, I use another another software called YACC and an abstract syntax tree (AST) gets created. Based off of this AST, I use depth first search and recursion to create ILOC. I keep track of variable names and assignments by using a lookup table. Due to the nature of this assignment, I used a linked list for the lookup table because of it was simple to implement. However, the lookup table would have been more efficient if I used a hash table instead. Overall, this project taught me a lot about data structures, algorithms, and the compilation process. Here's a link to the Github repository if you want to check it out https://github.com/JeremyPersing/baby-c-compiler.
What I Learned
- Became more comfortable developing in the C language and using pointers
- Practical uses for algorithms such as Depth First Search
- Practical uses for data structures such as linked lists, hash tables, graphs, and trees
- The compilation process
- Regular expressions and how to create grammars in code
- LR(1) and LL(1) parsing