This project is a C language compiler that includes a lexer, parser, semantic analyzer, and TAC (Three Address Code) generator. It was developed by Morteza Mahdi Zadeh and Soheil Nouhi.
The compiler uses ANTLR to define the grammar for the C language. The grammar supports the following features:
- Function Declarations:
int main() { ... }
- Statements:
- Expression statements (
x = 10;
) - Return statements (
return x;
) - Blocks (
{ ... }
) - Printf statements (
printf("value is %d", x);
) - Control structures:
- If-Else Statements (
if (x < 10) { ... } else { ... }
) - While Loops (
while (x > 0) { ... }
) - For Loops (
for (int i = 0; i < 10; i++) { ... }
)
- If-Else Statements (
- Expression statements (
- Variable Declarations and Assignments:
- Supported types:
int
,float
,char
,void
- Example:
int x = 10;
- Supported types:
- Expressions:
- Arithmetic operations (
+
,-
,*
,/
,^
) - Comparison operators (
<
,>
,<=
,>=
,==
,!=
) - String, character, and numeric constants.
- Arithmetic operations (
The project is organized into the following packages:
org.compiler.antlr
: Contains theCLang.g4
grammar file.org.compiler.lexer
: Contains theCLangLexer
for tokenizing the source code.org.compiler.parser
: Includes:CLangParser
for parsing the tokens.CLangBaseListener
andCLangBaseVisitor
interfaces and their implementations.
org.compiler.semantic
: Contains theSemanticAnalyzer
for scope and type checking.org.compiler.tac
: Contains:TacGenerator
for generating three-address code.TacInstruction
for representing TAC instructions.
git clone https://github.com/Morteza363831/compiler.git
cd compiler
mvn exec:java -Dexec.mainClass="org.compiler.Main"
mvn clean package
A precompiled JAR file is available in the Releases section. To run it :
java -jar compiler-1.0.jar
Thanks to the following developers for their contributions:
- I added sections for features, contributors, and instructions for running the project.
- If there's any additional information you'd like, let me know!
- Morteza Mahdi Zadeh's email : [email protected]
- Soheil Nouhi's email : [email protected]