Skip to content

edocecchini01/miniC-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MiniC Compiler

A simplified compiler for a subset of the C programming language, built in Java using JFlex and CUP.

✨ Features

  • 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
    • print statements for output

🛠️ Build & Usage

# 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

📝 Supported Code Example

// 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;
}

📂 Project Structure

  • scanner.jflex - Lexer definition
  • parser.cup - Parser grammar
  • Main.java - Compiler entry point
  • bubble.c - Bubble sort algorithm example

Educational project for learning compilation concepts

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors