Thursday, March 26, 2009

Implementing a SQL Parser using JavaCC - 1

JavaCC is the Compiler compiler implementation written in Java. What this means is JavaCC lets you define the grammar for any language and JavaCC will generate java classes that lets you to read, analyze and break the input into language units. Essentially, JavaCC generates parser and lexical analyser for you from the grammar file that you provided.

Every language is made up of set of alphabets. These alphabets are composed into meaningful units called words. These words are then composed into meaningful sentences. For implementing a SQL Parser, lets see how these language units compare
Alphatets - No particular equivalent in SQL
Words - Valid SQL Tokens like SELECT, INSERT, UPDATE, DELETE, CREATE, etc
Sentence - Valid ordering of various SQL Tokens i.e., Valid SQL Statement.
For eg., SELECT A from TABLE_1 is valid whereas SELECT INSERT VIEW is gibberish and is not valid.

No comments:

Post a Comment