[antlr-interest] Left recursion

Thomas Brandon tbrandonau at gmail.com
Thu Jul 26 09:27:04 PDT 2007


On 7/27/07, mitchellch <mitchellch at comcast.net> wrote:
> I feel like there must be an obvious answer for this one, but I can't find
> it in the book or on the site.
>
> Given that ANTLR doesn't support left-recursion, how do I specify a grammar
> for arbitrarily nested blocks?
Modified from cminus example:
block
    :  '{'
       ( stat )*
       '}'
    ;

stat
    : forStat
    | expr ';'
    | block
    | assignStat ';'
    | ';'
    ;

Tom.
>
>
>
> For example,
>
>
>
> void method() {
>
>             { /* nested block */
>
>                         { /* nested block */
>
>
> double-nested-statement;
>
>                         }
>
>                         nested-statement;
>
>             }
>
>             unnested-statement;
>
> }
>
>
>
> -Mitch Christensen


More information about the antlr-interest mailing list