[antlr-interest] Problem generating the Java parser for Oracle PL/SQL grammar

Andrew Haritonkin thikone at gmail.com
Sun Nov 9 17:33:54 PST 2008


Hi, Javier Luis Cánovas Izquierdo!

You don't need so much memory for my grammar, really :) 256Mb is
enough for ANTLR v3.1.1. Well I use 512Mb actually...

You need to change one rule though, to make it compatible with ANTLR 3.1.x:

column_spec
   :       sql_identifier ( DOT sql_identifier )*;

For some reason, ANTLR 3.1.x cannot compile it, raising a error:

error(206): PLSQL3.g:791:4: Alternative 2: after matching input such
as ID DOT ID DOT ID DOT ID DOT decision cannot predict what comes next
due to recursion overflow to expr_add from sql_expression and to
expr_mul from expr_add

While with ANTLR 3.0.1 it was compiling just fine... Anyway, replace
it with this:

column_spec
   :       sql_identifier ( DOT sql_identifier ( DOT sql_identifier )? )?;

And regarding Java target - there is not much you need to change, only
members declaration and some gate predicates:

options {
       language=Java;
       k=*;
       backtrack=true;
       memoize=true;
       output=AST;
}

@members {
   private boolean is_sql = false;
}

and all parser rules for keywords should like like this:

keyA : {PLSQL3Parser.this.input.LT(1).getText().toUpperCase().equals("A")}? ID;

Here I have to reference parser class, because this predicate can be
also embedded in DFA, but there only token type stream is available,
LT(1) returns token ID, integer... not very convenient. Gonna write
separate topic for this, eventually.

I also use Java target, mainly to debug the grammar in ANTLRWorks -
works perfectly.

Andrew


More information about the antlr-interest mailing list