[antlr-interest] best way to deal with nested statements

michael micha-1 at fantasymail.de
Mon Jun 28 00:47:55 PDT 2010

On Friday 25 June 2010 16:36:43 Scherer Markus wrote:
> 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 :-/.

this is like switching the lexer language during lexing. There are discussions 
here that antlr is able so simulate packrat parsing (like rats!), which can 
handle that (you need to enable backtracking for unlimited lookahead and 
memoizing), but I'm not sure about it.
You could also use another lexer like jflex with antlr which has lexer states 
to handle that.

But if your pl_sql_block_content (or stuff) includes a statement with a string 
which includes your 'END' keyword, your splitter doesn't work anymore. So you 
may need to lex strings in pl_sql_block_content (or stuff).


More information about the antlr-interest mailing list