Supported statements
Databas currently supports three core SQL statements:SELECT- Query data from tables or evaluate expressionsINSERT- Insert rows into tablesCREATE TABLE- Define new tables with columns and constraints
;).
Architecture
The SQL parser is organized into several modules:Lexer
The lexer (databas_sql_parser/src/lexer/) tokenizes SQL input into tokens. It recognizes:
- Keywords (
SELECT,FROM,WHERE, etc.) - Identifiers (table and column names)
- Literals (strings, integers, floats, booleans)
- Operators (
+,-,*,/,==,!=,<,>,<=,>=) - Delimiters (parentheses, commas, semicolons)
Parser
The parser (databas_sql_parser/src/parser/) builds an abstract syntax tree (AST) from tokens:
- Statement parser - Parses top-level statements
- Expression parser - Uses Pratt parsing with operator precedence
- Operator handling - Manages both prefix and infix operators
Usage example
Limitations
The current implementation has several intentional limitations:Parser features
The parser includes several notable features:Case-insensitive keywords
SQL keywords are case-insensitive. You can writeSELECT, select, or SeLeCt.
Expression precedence
The parser correctly handles operator precedence:Aggregate functions
You can use aggregate functions in SELECT statements:COUNT, SUM, AVG, MIN, MAX, STDDEV.
Error handling
The parser provides detailed error messages with position information:Next steps
SQL statements
Learn about SELECT, INSERT, and CREATE TABLE syntax
Expressions
Explore expression syntax and operators