[antlr-interest] Re: Preventing antlr from calling required rule

Oliver Zeigermann oliver at zeigermann.de
Sun Jul 27 01:09:51 PDT 2003


Hi!

Your grammar seems to be quite unusual. I was wondering if there 
isn't a better way to achive what you want. 

Anyway, if this is what you want to do you might use semantic 
predicates: Set some sort of flag when RuleA is matched in RuleB and 
check for it before calling rule RuleA from MainRule.

Can not check this now, but should work like this:

<after class decl>
{
  private ruleAFlag = false;
}

MainRule
     : RuleB
       { !ruleAFlag }? RuleA
     ;

RuleA
     : //
     ;

RuleB
     : (another rule
       | RuleA { ruleAFlag = true; }
     )
     ;

Hope this helps,

Oliver

P.S.: When using this in combination with syntactic predicates you 
might run into trouble as execution of code ("ruleAFlag = true") in 
guessing mode is switchted off.


--- In antlr-interest at yahoogroups.com, "mazlanmat" <mazlanmat at y...> 
wrote:
> Hello there
> Is is possible to prevent antlr from calling required rule(let say
> RuleA) after the same rule (RuleA) has been matched in the subrule
> (RuleB)
> Example:
> MainRule
>      : RuleB
>        RuleA
> 
> RuleA
>      : //
>      ;
> 
> RuleB
>      : (another rule
>        | RuleA
>      )
>      ;
> 
> In the mainRule above, RuleA must be matched after RuleB, but RuleB
> also might contains RuleA.The problem here is that after RuleA has
> been matched in RuleB, MainRule will always try to match RuleA 
(which
> is already been matched)
> 
> 
> Thanks
> Mazlan


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list