A lightweight, mini relational Database Management System (DBMS) built from scratch in C, with a custom lexer and parser powered by Flex and Bison.
- About
- Features
- Project Structure
- Tech Stack
- Prerequisites
- Build Instructions
- Usage
- How It Works
- Contributing
- Author
MINIDB is a command-line database engine built as a systems programming project. It implements a subset of SQL, including the ability to create tables, insert records, and query data — all managed through a hand-crafted parser and a file-backed storage engine written in pure C.
This project demonstrates low-level concepts such as lexical analysis, parsing, table storage, and query execution without relying on any third-party database libraries.
- Custom SQL-like query parser using Flex (lexer) and Bison (parser)
- Support for basic DDL and DML operations (CREATE TABLE, INSERT, SELECT)
- File-backed persistent storage engine
- Modular architecture with clean separation between lexer, parser, executor, and storage layers
- Windows-native build script (
build.bat) - Lightweight — no external database dependencies
MINIDB/
├── include/ # Header files
│ ├──db.h
│ ├──executor.h
│ ├──storage.h
│ ├──table.h
│ ├──utils.h
├── src/
│ ├── main.c # Entry point
│ ├── db.c # Core database logic
│ ├── table.c # Table management
│ ├── storage.c # File-backed storage engine
│ ├── executor.c # Query execution engine
│ ├── utils.c # Utility functions
│ ├── lexer.l # Flex lexer definition
│ └── parser.y # Bison grammar/parser definition
├── build/ # Compiled object files and executable (auto-generated)
├── build.bat # Windows build script
└── README.md
| Component | Technology |
|---|---|
| Language | C |
| Lexer | Flex (Lex) |
| Parser | Bison (YACC) |
| Build System | Batch Script (Windows) |
| Compiler | GCC |
Make sure the following tools are installed and available in your system PATH:
- GCC — C compiler (e.g., via MinGW-w64 on Windows)
- Flex — Lexical analyser generator
- Bison — Parser generator (GNU Bison)
You can verify they are available by running:
gcc --version
flex --version
bison --versionClone the repository and run the build script:
git clone https://github.com/Sagar0810k/MINIDB.git
cd MINIDB
build.batThe build script will:
- Clean any previously generated files
- Generate the parser using Bison (
parser.y→parser.tab.c / .h) - Generate the lexer using Flex (
lexer.l→lex.yy.c) - Compile all source files individually
- Link everything into a final executable:
build/minidb.exe
After a successful build, run the executable from the project root:
build\minidb.exeYou will be presented with a prompt where you can enter SQL-like commands, for example:
CREATE TABLE students (id INT, name TEXT, age INT);
INSERT INTO students VALUES (1, 'Alice', 21);
SELECT * FROM students;MINIDB is structured as a pipeline:
User Input
│
▼
Lexer (Flex) ← Tokenizes raw SQL text
│
▼
Parser (Bison) ← Validates grammar, builds AST
│
▼
Executor ← Interprets and executes commands
│
▼
Storage Engine ← Reads/writes table data to disk
Each layer is independently compiled and linked together. The include/ directory contains shared header files that define data structures used across all modules.
Contributions, suggestions, and bug reports are welcome!
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature/your-feature) - Open a Pull Request
Sagar Singh Rawat
GitHub: @Sagar0810k
Built with 💻 and a lot of
segmentation faultdebugging.