This directory contains the implementation of a simple C compiler focusing on while loops. The compiler is designed to translate C code with while loops into assembly language.
- Lexer: Breaks down the input C code into tokens.
- Parser: Analyzes the structure of the code and builds an Abstract Syntax Tree (AST).
- Code Generator: Converts the AST into assembly code.
- The compiler reads the input C file containing while loops.
- The lexer tokenizes the input, identifying keywords, identifiers, and symbols.
- The parser constructs an AST, representing the structure of the while loop and its body.
To compile a C file with while loops:
- Place your C source file in the input directory.
- Run the compiler:
./compiler input/your_file.c - The resulting assembly code will be in the output directory.
To execute specific phases of the compiler:
- Navigate to the relevant directory (e.g.,
01Lexical/,02SyntaxTree/, or03LRParser/). - Compile and run the corresponding source file (e.g.,
lexical.cpp,SyntaxPhase.cpp, orshiftreduce.cpp).
For example:
cd Compiler/01Lexical/
g++ lexical.cpp -o lexicalAnalyzer
./lexicalAnalyzer- C++ compiler for compiling the source files.
- Input files such as
input.c,While.c, andrules.txtas required by specific phases.