A C++ style language compiler written in C++, using Lex/Flex for lexical analysis and YACC/Bison for parsing. The compiler generates x86-64 Intel syntax assembly, assembled with NASM and linked with LD.
g++(C++ compiler)flex(lexer generator)bison(parser generator)nasm(assembler)ld(linker)
This compiler was developed as part of the Compiler Design course. It is divided into four assignments:
- Assignment 1: Lexical Analysis Phase
- Assignment 2: Parsing Phase
- Assignment 3: Semantic Analysis and Three Address Code (3AC) Generation
- Assignment 4: Assembly Code Generation
To run the project:
- Add the test case in the
testingfolder inside Assignment 4. - Use
./run.shto generate the assembly. - Use
./run1.shto run the generated assembly.
intlongdoublefloatshortchar
- Explicit type casting: Uses the syntax
(type) expression - Implicit type casting: Performed during assignments and when returning values from functions
class ClassName {
public: {
int a;
float b;
}
private: {
double c;
}
};- Function calling, including variable argument functions (ellipses)
- Control flow constructs:
if-else, nested if-else,for,while,do-while,untilloops - Data structures:
struct,union,enum,typedef - Object-oriented features:
classdefinitions, object creation and usage, inheritance, and access modifiers (public,private,protected) - Memory management: dynamic memory allocation, multilevel pointers and arrays
- Modifiers:
static,constkeywords - Input/Output:
printf,scanf - Pointer operations
- Jump controls:
goto,break,continue - Arithmetic and logical operators
- Recursive function calls
- Function calling
- Loops:
for,while,do-while,until - Conditional constructs:
if-else,switch-case - Type conversions (automatic and explicit)
- Pointer operations
- Input/Output:
printf,scanf - Jump controls:
goto,break,continue
- Support for division operations in assembly
- Handling global variables and
staticvariables with proper.dataand.bsssections - Implementation of advanced arithmetic expressions with short-circuit logic (
||,&&) integrated into arithmetic - Support for assignment to variables referenced through pointers
- Handling of member function calls for
classobjects - Support for passing arrays and structs as arguments
- Support for returning values beyond integers (e.g., structs, floats, etc.)
- Support for implicit type conversions
- PARIT
- PRATYAKSH
- RONIT
- AVIRAL