[antlr-interest] ANTLR Grammar for SELECT statement

Alexander Brown abrown at analytics8.com
Thu Apr 2 18:02:17 PDT 2009


Unless you are parsing a set of very very simple statments then the short answer is no.  There is no such thing as a simple grammar that can parse SELECT and INSERT statements.  The complexity is that practically anywhere you can have a simple identifier (like a column name), you can have a complex expression, up to and including a fully specified subquery.  As soon as you hit such a situation, things become very complicated.  Because of the way SQL is defined, you are almost guaranteed to hit this situation very quickly- likely when you start to think about the WHERE clause.
 
If you base your parser on the SQL2003 spec, you will need about 600 lexer and parser rules to handle what I would consider the core SQL SELECT, INSERT, UPDATE syntax. 
 
Alex
 
Alexander Brown
Partner | Analytics 8 | Tel +61 2 9299 4430 | Mob +61 424 043 485| abrown at analytics8.com | www.analytics8.com

________________________________

From: antlr-interest-bounces at antlr.org on behalf of antlr-interest-request at antlr.org
Sent: Fri 4/3/2009 06:00
To: antlr-interest at antlr.org
Subject: antlr-interest Digest, Vol 53, Issue 3



------------------------------

Message: 25
Date: Thu, 2 Apr 2009 23:08:42 +0530
From: Ramakrishnan Venkataramani
        <ramakrishnan.venkataramani at gmail.com>
Subject: [antlr-interest] ANTLR Grammar for SELECT statement
To: antlr-interest at antlr.org
Message-ID:
        <f4c143ea0904021038q23a5e868p79fd6056e1f29e00 at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

 Hello,
I am new to ANTLR. I am looking for a very simple SQL statement like SELECT
and INSERT written in ANTLR grammar. I am also looking for the corresponding
lexer, parser, and the test file (which reads the lexer, parser files and
produces output). I saw the grammar *for PL/SQL*
http://www.antlr.org/grammar/1209225566284/PLSQL3.g, it was so good, but it
was humongous. so if possible can you please send me a simple ANTLR grammar
for SELECT, INSERT.

Thanks a lot for your kindly help

Regards
Ramakrishnan


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090402/474a14d0/attachment.html 


More information about the antlr-interest mailing list