[antlr-interest] Help on parsing SQL statements

Andi Clemens Andi.Clemens at gmx.net
Tue Apr 6 04:32:10 PDT 2010


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


More information about the antlr-interest mailing list