CompilerC is a modular compiler written in C++ designed for parsing, analyzing, and generating assembly code from custom programming languages. his project includes a lexer, an Abstract Syntax Tree (AST) parser, and an assembler code generator.
- Lexer: Tokenizes input source code into meaningful lexical tokens using regular expressions.
- AST Parser: Constructs an Abstract Syntax Tree (AST) to represent the syntactic structure of the code.
- Assembler Generator: Produces assembly code from the AST, enabling low-level execution.
lexer.hpp
: Header file implementing the lexer for tokenizing source code.compiler.hpp
: Includes core compiler logic, including AST parsing.main.cpp
: The main entry point of the application.test/
: Contains unit and integration tests for the lexer, parser, and assembler generator.
-
Lexical Analysis: The lexer reads the input code and produces a stream of tokens such as keywords, literals, operators, and delimiters.
-
Syntax Analysis (AST Parser): The parser processes tokens and generates an Abstract Syntax Tree (AST) that represents the syntactic structure of the code.
-
Code Generation: The assembler generator translates the AST into assembly code for execution on the target architecture.
- C++17 or later: Required for modern C++ features.
- CMake: To configure and build the project.
- A C++ Compiler: GCC, Clang, or MSVC.
-
Clone the repository:
git clone <repository-url> cd compilerC
-
Create and navigate to the build directory:
mkdir build cd build
-
Configure and build the project:
cmake .. make
After building, execute the program:
./compilerC <source_file>
Replace <source_file>
with the path to your source code.
To ensure the components are functioning correctly, the test/
directory includes unit tests. Run tests using CTest:
cd build
ctest
Sample input code:
int main() {
return 42;
}
Generated assembly code:
.section .text
.global _start
_start:
mov $42, %eax
ret
This project is licensed under the terms specified in the LICENSE
file.
Contributions are welcome! Feel free to fork the repository and submit pull requests.
For any questions or further details, please contact the maintainers.