# antoniiolpzzz/comp-miniccompiler architecture

> Architecture diagram of the GitHub repository antoniiolpzzz/comp-miniccompiler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/antoniiolpzzz/comp-miniccompiler
- Repository: https://github.com/antoniiolpzzz/comp-miniccompiler

## Overview

The MiniC Compiler project is a dedicated educational compiler developed for a university compilers course. It is designed to compile a simplified C-like language (miniC) through the common compilation phases: lexical analysis, syntactic analysis, and semantic analysis. The project uses C as its core language, augmented by Flex for tokenizing source code and Bison for parsing according to defined grammar rules.

##### Main Components
- Compiler Main (miniCCompilerMain.c): Acts as the entry point of the application.
- Lexical Analysis Module (Directory: Lexical):
- File: miniCLexical.l
- Role: Uses Flex to generate tokens from the input miniC source file.
- Syntactic Analysis Module (Directory: Syntactic):
- File: miniCSyntactic.y
- Role: Uses Bison to parse the token stream and enforce language grammar rules.
- Semantic Analysis Module (Directory: Semantic):
- Files: miniCCodeList.c/h, miniCSymbolTable.c/h
- Role: Manages the symbol table and possibly intermediate code (or code list creation) to form the semantic (or later code generation) part of compiling.
- Build/Execution Components:
- Makefile: Orchestrates the build process.
- testFile.mc: Serves as an example input file for demonstration/testing.

##### Relationships and Interactions
- The process begins with the execution of the compiler (invoked via the Makefile or directly running miniCCompilerMain).
- The compiler reads the input file (e.g., testFile.mc) and passes it to the Lexical Analyzer.
- The Lexical Analyzer (via miniCLexical.l) tokenizes the input and sends a stream of tokens to the Syntactic Analyzer.
- The Syntactic Analyzer (through miniCSyntactic.y) uses these tokens to build a parse tree according to the miniC grammar and, during this process, invokes routines from the Semantic Analysis module.
- The Semantic Analysis module (using components like miniCSymbolTable and miniCCodeList) validates correct semantic usage (e.g., symbol declarations, code lists for further processing) and likely prepares the compiled output.
- Finally, the compiler produces an output (an executable or an assembly file, as indicated in the README via redirection to compiledfile.s).

##### Architectural Patterns and Technologies
- Pipeline Pattern: The compiler’s modules are organized in a sequential pipeline (Lexical → Syntactic → Semantic) which is typical for compiler design.
- Separation of Concerns: Each major phase (lexical, syntactic, semantic) has its own dedicated module/folder.
- Use of Industry-standard Tools: Flex handles tokenization whereas Bison manages the parsing phase.
- Integration via Build System: The Makefile coordinates the build process, demonstrating a simple but effective continuous integration mechanism within the project.

##### Final Recommendations
- Be as detailed as possible to capture all key interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Build["Build System (Makefile)"]:::build
    InputSource["Input Source (testFile.mc)"]:::input
    CompilerMain["Compiler Main"]:::compiler
    Lexical["Lexical Analysis Module"]:::lexer
    Syntactic["Syntactic Analysis Module"]:::parser
    CodeListC["CodeList.c"]:::semantic
    CodeListH["CodeList.h"]:::semantic
    SymbolTableC["SymbolTable.c"]:::semantic
    SymbolTableH["SymbolTable.h"]:::semantic
    SemanticOutput["Semantic Analysis Output"]:::output

    %% Build and Input feed into Compiler Main
    Build --> CompilerMain
    InputSource --> CompilerMain

    %% Compiler pipeline
    CompilerMain --> Lexical
    Lexical --> Syntactic

    %% Semantic Analysis Branch - Code List Flow
    Syntactic --> CodeListC
    CodeListC --> CodeListH
    CodeListH --> SemanticOutput

    %% Semantic Analysis Branch - Symbol Table Flow
    Syntactic --> SymbolTableC
    SymbolTableC --> SymbolTableH
    SymbolTableH --> SemanticOutput

    %% Final output returned to Compiler Main
    SemanticOutput --> CompilerMain

    %% Click Events
    click CompilerMain "https://github.com/antoniiolpzzz/comp-miniccompiler/blob/main/miniCCompilerMain.c"
    click Lexical "https://github.com/antoniiolpzzz/comp-miniccompiler/blob/main/Lexical/miniCLexical.l"
    click Syntactic "https://github.com/antoniiolpzzz/comp-miniccompiler/blob/main/Syntactic/miniCSyntactic.y"
    click CodeListC "https://github.com/antoniiolpzzz/comp-miniccompiler/blob/main/Semantic/miniCCodeList.c"
    click CodeListH "https://github.com/antoniiolpzzz/comp-miniccompiler/blob/main/Semantic/miniCCodeList.h"
    click SymbolTableC "https://github.com/antoniiolpzzz/comp-miniccompiler/blob/main/Semantic/miniCSymbolTable.c"
    click SymbolTableH "https://github.com/antoniiolpzzz/comp-miniccompiler/blob/main/Semantic/miniCSymbolTable.h"
    click Build "https://github.com/antoniiolpzzz/comp-miniccompiler/tree/main/Makefile"
    click InputSource "https://github.com/antoniiolpzzz/comp-miniccompiler/blob/main/testFile.mc"

    %% Styles
    classDef compiler fill:#AED6F1,stroke:#2E86C1,stroke-width:2px;
    classDef lexer fill:#F9E79F,stroke:#F5B041,stroke-width:2px;
    classDef parser fill:#A9DFBF,stroke:#28B463,stroke-width:2px;
    classDef semantic fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
    classDef build fill:#F5CBA7,stroke:#E67E22,stroke-width:2px;
    classDef input fill:#D5F5E3,stroke:#1ABC9C,stroke-width:2px;
    classDef output fill:#FAD7A0,stroke:#F39C12,stroke-width:2px;
```
