[antlr-interest] Matching braces in grammar

Jukkis evangelion at luukku.com
Mon May 21 06:12:37 PDT 2007


> Basically you need to replace STRING_LITERAL with something
> like that:
>
> beanshell_statement
>      : "$" LCURLY! block+ RCURLY!
>      ;
> 
> block
>    :   text
>    |   LCURLY text RCURLY
>    ;
> 
> Best regards,
> Johannes Luber

Hello again, and thank you for your quick response Johannes! However, I feel this solves only part of the problem -- because BeanShell code can have any number of nested curly-brace delimited blocks. Obviously, we cannot just write

block
    : block
    | LCURLY block RCURLY
    ;

since this would lead to an infinite recursion rule, the kind which is not allowed in ANTLR. Also, for the same reason, we cannot refer to the 'block' rule from any rule whose ancestor 'block' is, if I have understood correctly.

Any ideas how to solve the nested blocks problem?

Thanks!




...................................................................
Luukku Plus paketilla pääset eroon tila- ja turvallisuusongelmista.
Hanki Luukku Plus ja helpotat elämääsi. http://www.mtv3.fi/luukku



More information about the antlr-interest mailing list