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

Andrew Bradnan andrew.bradnan at gmail.com
Mon Jun 28 10:28:51 PDT 2010


Since you know all the legal constructs why don't you just fill out the
lexer section.  Then you can use
stuff: word+ ;
word: id | Number | StringLiteral | operator | etc ;
It's a tad more work, but it's easy.
On Mon, Jun 28, 2010 at 12:47 AM, michael <micha-1 at fantasymail.de> wrote:

> 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).
>
> cheers,
>  Michael
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>



-- 
/Andrew


More information about the antlr-interest mailing list