A compiler for the COOL programming language. It accepts a COOL program, and outputs equivalent LLVM IR. This project implements a parser, semantic analyzer and a code generator. An implementation of a lexical analyzer for COOL can be found here. The compiler has been implemented in Java.
- Parser: Converts tokens provided by the lexical analyzer into an abstract syntax tree (AST), in accordance to the grammar rules of COOL. Flags errors if any grammar rule is violated.
- Semantic Analyzer: Type checks the parsed program according to the type rules of COOL, and annotates each AST node with a type. Flags errors if any semantic or type rules are violated, for example, the case where the input program calls non-existent methods or performs an invalid type conversion.
- Code Generator: Converts the annotated AST into LLVM intermediate representation (IR). At some points, code might be inserted to handle run-time errors. The LLVM IR can then be converted to machine code by clang, the LLVM frontend, and executed.
The compiler implements a restricted version of COOL, i.e., some of the constructs in the language specification are not covered.