C- Compiler done for COP4610 (Compilers)
Note that the compiler is left intentionally incomplete. It contains (later fixed) parsing/semantic analysis bugs and lacks code generation.
Compiler Design:
The task was to create a recursive descent Compiler for the C- language, a subset of the C language. The grammar has been modified to be LL(k) parsable.
The Compiler has 4 steps:
- Lexical Analysis: The Lexer (Lexical Analyzer) processes raw text using regular expressions and a boolean flag state for comments. This converts the raw text into an analyzable arraylist of tokens. It supports all conventions of the C- language, including short and long-form comments.
- Syntax Analysis (Parsing): The Syntactic Analyzer (Parser) examines the arraylist of tokens generated by the Lexer to determine whether or not it conforms to the grammar. The version of the parser left in this repository is not the final version, and contains several bugs.
- Semantic Analysis: The Semantic Analyzer examines the arraylist of tokens in context and determines whether or not it conforms to the semantic rules of C-, as well as broadly logical considerations, like assigning numbers to number variables.
- Code Generation: The compiler generates assembly code. In the case of this compiler, it generates a set of quadruples that conform to the (nonexistant) assembly language specified by the professor. This repository does not contain code generation.