[antlr-interest] Problem writing a Grammar
Nicolai Mainiero
lists at mainiero.de
Mon May 7 08:20:07 PDT 2007
Hi,
thank you very much. You solved my problem. I will clean the grammar
file a bit and then provide it for download. Of course all helpers
will be credited in the comment.
Nicolai
Am 04.05.2007 um 14:23 schrieb Gavin Lambert:
> At 22:53 4/05/2007, lists at mainiero.de wrote:
> >Aborting because the following rules are mutually left-recursive:
> > [functioncall, prefixexp, var]
> >
> >Perhaps anyone can have a look at it to give me hints or solutions
> >how to get this grammar correct. I'm willing to donate this
> >grammar, to make it available on the ANTLR side.
>
> With a bit of rearranging and some assistance from ANTLRworks'
> automatic left-recursion-remover, I've come up with this (not
> totally sure it matches the original, but I think it does):
>
> varOrExp: var | '(' exp ')';
> nameAndArgs: (':' NAME)? args;
> varSuffix: nameAndArgs* ('[' exp ']' | '.' NAME);
>
> var: (NAME | '(' exp ')' varSuffix) varSuffix*;
> prefixexp: varOrExp nameAndArgs*;
> functioncall: varOrExp nameAndArgs+;
>
> (You can probably come up with better names for the first three
> rules.) :)
>
> Basically I did this by taking each of the last three rules in
> isolation, then inlining any references it made to one of the other
> problem rules, rearranging and extracting subrules out until I got
> a simple left-recursion, then using ANTLRworks' "Remove Left
> Recursion" function, and finally tidying up the result a bit.
>
More information about the antlr-interest
mailing list