# youneskr/lex-yacc-sql-compiler architecture

> Architecture diagram of the GitHub repository youneskr/lex-yacc-sql-compiler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/youneskr/lex-yacc-sql-compiler
- Repository: https://github.com/youneskr/lex-yacc-sql-compiler

## Overview

##### Project Type and Purpose
- This is a compiler/validator for a subset of SQL queries with a real-time GUI front end.
- It uses Flex (Lex) for tokenization, Bison (Yacc) for parsing, and a Python/Tkinter GUI for user interaction.

##### File Structure Analysis
- Top-level source artifacts:
– lex.l   Lex specification for lexical analysis
– synt.y   Yacc grammar for syntax analysis
– application.py Python GUI front end
- Build & cleanup scripts:
– compile.sh Wraps flex, yacc, gcc invocations to build the parser executable
– clear.sh  Cleans up generated files (lex.yy.c, y.tab.c/h, binary)
- Supporting files:
– sql_list.txt Sample SQL queries for import
– README.md/.gitignore

##### README Insights
- Confirms workflow: flex → yacc → gcc → `sql_parser`
- GUI uses Python 3 + tkinter + ttkbootstrap to invoke the compiled parser or run in CLI mode
- No external database; it only validates SQL syntax

a. Main Components
1. Build Pipeline
- Flex (lex.l) → generates lex.yy.c
- Bison (synt.y) → generates y.tab.c + y.tab.h
- GCC → compiles C sources + flex/yacc outputs into `sql_parser` executable
2. Runtime Environment
- Python GUI (application.py)
- SQL Parser Executable (`sql_parser`)
- Sample SQL file loader (sql_list.txt)
b. Relationships & Data Flows
- Build Pipeline components flow sequentially (Flex → Yacc → GCC) producing `sql_parser`
- At runtime:
– User enters SQL (or imports sql_list.txt) in the GUI
– GUI spawns `sql_parser` as a subprocess (or calls CLI mode) passing the SQL text
– `sql_parser` performs lexical analysis (Flex engine) → parsing (Yacc engine) → returns success or error messages
c. Architectural Patterns & Principles
- Compiler front-end pipeline: clear separation of lexing and parsing stages
- Modular build scripts encapsulate toolchain calls
- Decoupled GUI ↔ parser communication via subprocess interface
d. Key Technologies
- flex (Lex) – token definitions in lex.l
- bison (Yacc) – grammar rules in synt.y
- C (GCC) – core parser implementation
- Python + tkinter + ttkbootstrap – GUI layer

##### Essential Elements
- Clear component labels (e.g., “Lexer,” “Parser,” “GUI”)
- Call out any generated artifacts (lex.yy.c, y.tab.c/h, sql_parser)

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Build Pipeline"
    Compile["compile.sh"]:::buildTool
    Clean["clear.sh"]:::buildTool
    Flex["Flex (lex.l)"]:::buildTool
    Bison["Bison (synt.y)"]:::buildTool
    GCC["GCC → sql_parser"]:::buildTool
  end

  Compile --> Flex
  Flex -->|"lex.yy.c"| Bison
  Bison -->|"y.tab.c & y.tab.h"| GCC
  Clean -.->|"removes lex.yy.c"| Flex
  Clean -.->|"removes y.tab.c/h"| Bison
  Clean -.->|"removes sql_parser"| GCC

  subgraph "Runtime Environment"
    Loader["Sample SQL Loader (sql_list.txt)"]:::data
    GUI["Python GUI (application.py)"]:::runtime
    ParserExe["sql_parser executable"]:::runtime
  end

  Loader -->|"load queries"| GUI
  GUI -->|"spawn parser subprocess"| ParserExe
  ParserExe -->|"tokens & AST/errors"| GUI

  subgraph "Documentation"
    Readme["README.md"]:::docs
    Gitignore[".gitignore"]:::docs
  end

  click Flex "https://github.com/youneskr/lex-yacc-sql-compiler/blob/main/lex.l"
  click Bison "https://github.com/youneskr/lex-yacc-sql-compiler/blob/main/synt.y"
  click Compile "https://github.com/youneskr/lex-yacc-sql-compiler/blob/main/compile.sh"
  click Clean "https://github.com/youneskr/lex-yacc-sql-compiler/blob/main/clear.sh"
  click GUI "https://github.com/youneskr/lex-yacc-sql-compiler/blob/main/application.py"
  click Loader "https://github.com/youneskr/lex-yacc-sql-compiler/blob/main/sql_list.txt"
  click Readme "https://github.com/youneskr/lex-yacc-sql-compiler/blob/main/README.md"
  click Gitignore "https://github.com/youneskr/lex-yacc-sql-compiler/blob/main/.gitignore"

  classDef buildTool fill:#D6EAF8,stroke:#1B4F72,color:#1B2631,stroke-width:1px;
  classDef runtime fill:#D5F5E3,stroke:#196F3D,color:#0B5345,stroke-width:1px,stroke-dasharray: 5 5;
  classDef data fill:#FDEBD0,stroke:#B9770E,color:#7E5109,stroke-width:1px;
  classDef docs fill:#F4ECF7,stroke:#6C3483,color:#512E5F,stroke-width:1px,stroke-dasharray: 2 2;
```
