A simplified compiler for a subset of the C programming language, built in Java using JFlex and CUP.
- Lexical Analysis with JFlex - Token and identifier recognition
- Syntax Analysis with CUP - Expression and statement parsing
- Support for:
- Data types:
int,double - One-dimensional arrays
- Control structures:
if/else,while - Arithmetic and logical operators
printstatements for output
- Data types:
# Compile jflex
jflex scanner.jflex
# Compile cup
java java_cup.MainDrawTree parser.cup
javac *.java
# Run the compiler on a file
java Main bubble.c// Variable and array declaration
double x[5];
int i;
// Initialization
x[0] = 2.5;
i = 0;
// Control structures
while(i < 5){
if(x[i] > 0){
print x[i];
}
i = i + 1;
}scanner.jflex- Lexer definitionparser.cup- Parser grammarMain.java- Compiler entry pointbubble.c- Bubble sort algorithm example
Educational project for learning compilation concepts