How youneskr/lex-yacc-sql-compiler works
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)