Hi there antlr folk! As I have mentioned in a former thread I am currently working on a grammar that splits SQL*PLUS files in normal SQL-statements and PL/SQL-blocks.
The PL/SQL-blocks are a bit tricky, because the can contain nested blocks like
BEGIN
…
BEGIN
…
END;
END;
I thought about a mechanism, that increases a counter when a BEGIN is found and
decreases it when a END; is found:
@members {
int _iNestLevel = 0;
}
pl_sql_block
:
( ((BEGIN {System.out.println("begin (nestlevel: " +
(++_iNestLevel) + ")");})| DECLARE)
| CREATE (OR REPLACE
|PROCEDURE
|FUNCTION
|PACKAGE)
) pl_sql_block_content
;
pl_sql_block_content
: {_iNestLevel < 16}? (options {greedy=false;} : .)*
( BEGIN {System.out.println("begin
(nestlevel: " + (++_iNestLevel) + ")");}
| END SEMI{System.out.println("end
(nestlevel: " + (--_iNestLevel) + ")");})
( {_iNestLevel > 0}? pl_sql_block_content
)
;
I tried to eliminate recursion-issues with the predicates, but antlr
nevertheless considers the grammar wrong and throws following error when I try
to compile it:
[14:46:43] error(206): PLSQLSplitter.g:62:34: Alternative 2: after matching
input such as SEMI SL_COMMENT ML_COMMENT BEGIN BEGIN SEMI END SEMI END SEMI END
SEMI BEGIN decision cannot predict what comes next due to recursion overflow to
pl_sql_block_content from pl_sql_block_content
The second solution that came to my mind was a proper recursive grammar (like
e.g. the expression grammar from the book), but I think that’s a little
overkill for a simple splitter.
I attached the whole grammar in case the error isn’t obvious from the two rules
above.
Thanks in advance
Markus
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
PLSQLSplitter.g
Description: PLSQLSplitter.g
-- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
