Skip to content

HyP3RR/CompileX

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

247 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CompileX

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.


📦 Dependencies

  • g++ (C++ compiler)
  • flex (lexer generator)
  • bison (parser generator)
  • nasm (assembler)
  • ld (linker)

🏗️ Project Structure

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

🚀 Running the Project

To run the project:

  1. Add the test case in the testing folder inside Assignment 4.
  2. Use ./run.sh to generate the assembly.
  3. Use ./run1.sh to run the generated assembly.

✨ Features

Supported Data Types

  • int
  • long
  • double
  • float
  • short
  • char

Type Casting

  • Explicit type casting: Uses the syntax (type) expression
  • Implicit type casting: Performed during assignments and when returning values from functions

✅ IR-Level Features (Three Address Code - 3AC)

Class Syntax Example

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, until loops
  • Data structures: struct, union, enum, typedef
  • Object-oriented features: class definitions, object creation and usage, inheritance, and access modifiers (public, private, protected)
  • Memory management: dynamic memory allocation, multilevel pointers and arrays
  • Modifiers: static, const keywords
  • Input/Output: printf, scanf
  • Pointer operations
  • Jump controls: goto, break, continue
  • Arithmetic and logical operators
  • Recursive function calls

✅ Assembly-Level Features

  • 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

🧠 Future Work / Known Issues

  • Support for division operations in assembly
  • Handling global variables and static variables with proper .data and .bss sections
  • 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 class objects
  • Support for passing arrays and structs as arguments
  • Support for returning values beyond integers (e.g., structs, floats, etc.)
  • Support for implicit type conversions

👥 Contributors

  • PARIT
  • PRATYAKSH
  • RONIT
  • AVIRAL

About

A lightweight compiler for a C-style language with support for object-oriented features, type casting, and rich control flow, generating x86-64 assembly code from high-level constructs.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 62.0%
  • Yacc 26.1%
  • Lex 4.1%
  • C 3.4%
  • Assembly 1.8%
  • Python 1.4%
  • Other 1.2%