Write SQL. Compile it. See errors in real time.
A fully functional SQL compiler built from scratch using Flex (lexer) and Bison/Yacc (parser), with a dark-themed Python Tkinter GUI. Runs on Linux type or load SQL queries and get instant syntax validation with detailed error messages including line number and token location.
- 📝 Lexer (Flex) : tokenizes SQL keywords, identifiers, operators, and symbols
- 🧩 Parser (Bison/Yacc) : validates SQL grammar rules
- ✅ Supported SQL statements:
SELECT.. with*or column list, single or multiple tablesINSERT INTO ... VALUESUPDATE ... SET ... WHEREDELETE FROM ... WHERECREATE TABLE / DATABASEDROP TABLE / DATABASEALTER TABLE ... ADD
- 🔴 Detailed error messages : line number + unexpected token + expected token
- 🖥️ Tkinter GUI : dark VS Code-inspired interface with INPUT and OUTPUT panels
- 📂 File loading : load
.sqlor.txtfiles directly into the editor - 🔁 Case-insensitive : SQL keywords work in any case (
SELECT,select,Select)
| Empty Interface | Error Detection | Build Commands |
|---|---|---|
![]() |
![]() |
![]() |
sql-compiler/
├── lexer.l # Flex lexer : tokenization rules
├── parser.y # Bison parser : grammar rules + error reporting
├── interface.py # Python Tkinter GUI
└── screenshots/
⚙️ Generated files (
lex.yy.c,parser.tab.c,parser.tab.h,sql_compiler) are excluded from the repo build them locally using the commands below.
sudo apt install flex bison gcc python3# Step 1 : Generate lexer
flex lexer.l
# Step 2 : Generate parser
bison -d parser.y
# Step 3 : Compile
gcc parser.tab.c lex.yy.c -o sql_compiler
# Step 4 : Launch GUI
python3 interface.py- User types SQL in the INPUT panel or loads a
.sqlfile - GUI calls the compiled
sql_compilerbinary viasubprocess - Flex tokenizes the input identifies keywords, identifiers, operators
- Bison validates the token stream against SQL grammar rules
- Valid statements print:
Line X: Valid SELECT(or INSERT, CREATE, etc.) - Invalid statements print:
Line X | Error: syntax error | (At token: 'TOKEN') - Output displayed in color green for success, red for errors
Input:
CREATE DATABASE my_data;
SELECT * FROM users;
DROP TABLE old_records;
INSERT INTO logs VALUES (500);
SELECT name FROM users
DROP DATABASE temp;Output:
ERRORS
Line 6 | Error: syntax error, unexpected DROP, expecting SEMICOLON | (At token: 'DROP')
Line 5 is missing a semicolon — the compiler catches it precisely.
| Layer | Technology |
|---|---|
| Lexer | Flex (Fast Lexical Analyzer) |
| Parser | Bison / Yacc |
| Compiler | GCC |
| GUI | Python Tkinter |
| Platform | Linux / Lubuntu VM |
Sakni Tasnim
Telecommunications & Computer Engineering Student
🔗 GitHub • LinkedIn
Feel free to use, modify, and build on this project.


