Skip to content

hemanta212/SQL-Lexer-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Basic SQL Lexer/Parser

This is a very rudimentry sql lexing and parsing logic for use in sqlite toy implementation project.

Lexing technique is inspired by the Talk of Rob Pike on Lexing on go html/templating std lib

Examples:

Create Table

go run main.go
Scanning SQL:

	CREATE TABLE oranges
(
       id integer primary key autoincrement,
       name text,
       description text
)


Parsed Stmt:
&{create oranges {oranges [{id [integer primary key autoincrement]} {name [text]} {description [text]}]}}

Select statement

go run main.go
Scanning SQL:
 SELECT name, id from apples

Parsed Stmt:
&{select [name id] [apples] []}

Select statement with functions

go run main.go
Scanning SQL:
 SELECT Count(*) from apples, oranges

Parsed Stmt:
&{select [] [apples oranges] [{count [*]}]}

Reporting Errors

go run main.go
Scanning SQL:
 SELECT name, id, from apples, oranges
Parsing error: Unexpected trailing comma near "from" at line 1 pos 17
go run main.go
Scanning SQL:
 SELECT Count(name id) from apples, oranges
Parsing error: Missing comma between arguments near "id" at line 1 pos 18

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages