[antlr-interest] Help on parsing SQL statements

Jim Idle jimi at temporal-wave.com
Tue Apr 6 08:37:20 PDT 2010


Couple of pointers for you:

1) To use the grammar in any commercial way, you will probably need to change all those keywords in to real tokens in the lexer, otherwise you won't know what their symbols are for error messages and so on. Also constructing a tree/tree parser is a lot easier that way;
2) The generated code is large and VS2008 cannot debug more than 16384 code lines. To reduce you have to split the parser up into multiple imports;
3) The ANTLRWorks debugger only works with the development version of the C target and runtime as it went out of sync and I had no time to fix it for 3.2 - you can use the development snapshots if you are willing to build locally;
4) I have a commercial PL/SQL parser at: www.temporal-wave.com if you are in need of something commercial - you can test it online;

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Andi Clemens
> Sent: Tuesday, April 06, 2010 4:32 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Help on parsing SQL statements
> 
> Some more info:
> 
> I'm using the PL/SQL grammar for Oracle as a starting point and
> implement the missing SQL statements around it.
> 
> Unfortunately this code becomes so huge, I'm not able to compile a Java
> generator from it and therefore can't use the debugger in ANTLRworks.
> 
> My main target is "C", it compiles fine, but debugging is not that easy
> here.
> 
> Andi
> 
> -------- Original-Nachricht --------
> > Datum: Tue, 06 Apr 2010 13:23:30 +0200
> > Von: "Andi Clemens" <Andi.Clemens at gmx.net>
> > An: antlr-interest at antlr.org
> > Betreff: [antlr-interest] Help on parsing SQL statements
> 
> > Hi,
> >
> > I'm implementing a parser that returns the table_spec that is used in
> an
> > (Oracle)SQL-Statement. The parser decides whether the statement
> should be
> > executed or not.
> > I don't need all SQL statements that can occur, only the ones with
> > table_specs in it, like SELECT, INSERT, DELETE, CREATE TABLE etc.
> > In most cases I don't even need to know the whole SQL statement, only
> > parts of it. So I have rules that look something like this:
> >
> > alter_materialized_view_statement
> > 	:	'ALTER' 'MATERIALIZED' 'VIEW'
> > 		('LOG' 'FORCE'? 'ON')? table_spec .*
> > 	;
> >
> >
> > alter_view_statement
> > 	:	'ALTER' 'VIEW' table_spec
> > 		('ADD' | 'MODIFY' | 'DROP' | 'COMPILE') .*
> > 	;
> >
> >
> > But when I type in the following statement, the parser is not able to
> > parse it:
> >
> > ALTER VIEW schema.table [...];
> >
> > Also the next statement is not working:
> >
> > ALTER MATERIALIZED VIEW LOG ON schema.test [...];
> >
> >
> > Is it because I use ".*" in the rules? Why isn't ANTLR able to decide
> > which rule to use here? They clearly start differently.
> > I always get the following error:
> >
> > statementString(1)  : error 3 : , at offset -1
> >     near [Index: 0 (Start: 4058184-Stop: 4058188) ='alter', type<118>
> > Line: 1 LinePos:-1]
> >      : cannot match to any predicted input...
> >
> >
> > Any idea how to fix that?
> > In the end, I only want to have some statements checked (the one with
> > table_specs), other statements should be ignored (on parse error).
> >
> > Andi
> >
> > --
> > GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> > Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> > http://www.antlr.org/mailman/options/antlr-interest/your-email-
> address
> 
> --
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address





More information about the antlr-interest mailing list