A SQL parser implementation in Rust that supports SELECT and CREATE TABLE statements. This project was developed as part of the Programming Languages course.
-
Tokenizer that handles:
- SQL keywords (SELECT, CREATE, WHERE, etc.)
- Identifiers and literals
- Operators and special characters
- Numbers and strings
-
Pratt parser for expressions with proper operator precedence
-
SQL statement parser supporting:
- SELECT statements with WHERE and ORDER BY clauses
- CREATE TABLE statements with column constraints
- Error handling and informative error messages
src/tokenizer.rs- Implements the SQL tokenizersrc/parser.rs- Contains the Pratt parser and SQL statement parsersrc/token.rs- Defines token types and keywordssrc/statement.rs- Defines AST structures for SQL statements
To run the SQL parser:
- Clone the repository
- Run
cargo buildto build the project - Run
cargo runto start the interactive SQL parser - Enter SQL queries ending with semicolons
Example queries:
SELECT name, age FROM users WHERE age > 18;
CREATE TABLE products (id INT PRIMARY KEY, name VARCHAR(100));