Thanks for your quick response Gordon.
Unfortunately, this solution does not seem to work. If I define "stuff" as
generic as I want it to be (like (options {greedy=false;} : .)*)) it isn't able
to compile either (The following alternatives can never be matched: 2). I guess
because the END of a codeBlock would get matched by "stuff" in statement. If
define stuff as
stuff : (options {greedy=false;} : ~(END))* ;
it does not match all tokens I am interested in :-/.
-----Ursprüngliche Nachricht-----
Von: Gordon Tyler [mailto:[email protected]]
Gesendet: Freitag, 25. Juni 2010 15:53
An: Gordon Tyler; Scherer Markus; [email protected]
Betreff: RE: best way to deal with nested statements
Sorry, this should be better:
statement: (stuff|codeBlock) SEMI ;
codeBlock: BEGIN statement* END ;
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Gordon Tyler
Sent: June 25, 2010 9:51 AM
To: Scherer Markus; [email protected]
Subject: Re: [antlr-interest] best way to deal with nested statements
Why not something like this:
statements: (stuff|codeBlock);
codeBlock: BEGIN statements END;
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Scherer Markus
Sent: June 25, 2010 9:03 AM
To: [email protected]
Subject: [antlr-interest] best way to deal with nested statements
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
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
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.