This was my term project for the compilers course I took during Fall 2008 while at Millersville University.
Requirements
Scanner - Write a scanner (lexical analyzer) for the C- programming language described in Appendix A of the textbook, with the addition of FOR, INCREMENT, and DECREMENT keyword tokens. Use a Makefile to build your project. We will extend it to eventually build your full compiler. Code a flex specification file (use a dot el extension) and a driver program that invokes the generated scanner (yylex) and prints the token-lexeme pairs encountered in a C- program. Report any invalid input and the line number it occurs on.
Recognizer - In C++ write a recognizer for the C- programming language, augmented with for, pre-increment, and pre-decrement statements. Submit all relevant files, including a Makefile; your flex specification file; a bison specification file (use a dot yy extension); and a driver program that invokes the generated parser (yyparse) and indicates whether the inputted sentence is in the C- language.
Parser - Write a parser for the C- programming language. Build and print the abstract syntax tree (AST).
Symbol Table - Write symbol table routines declared in the provided files. After testing the routines, add semantic actions to your Bison specification file to manage names, pairing uses with declarations through declptr.
Code Generation - Write an IA-32 code generator module for C-. Include a write-up of your test cases and an analysis of what your compiler can and cannot handle.
Objectives
- Construct a lexical analyzer for the language using Flex
- Generate the required rules for an Bottom-Up parser for the language using Bison
- Build the Abstract Syntax Tree using a TreeNode derived class
- Process the symbol table using an unordered set
- Generate assembly code