[antlr-interest] Using previously matched parser rule in decision making

Jim Idle jimi at temporal-wave.com
Sun Mar 7 18:00:04 PST 2010


If it cabn be determined via prior tokens you can test the value of LA 
(-n). If not you can use a scope in a higher ruler than both and set a  
flag. But easier than that, pass a Boolean (or state if more than two  
rules). So ruleB[true] ruleB[false]. But if they are  duplicate then  
refactoring will be better usually.

ruleB[Boolean isA] :

Jim

On Mar 7, 2010, at 18:50, Kieran Simpson <kierans777 at gmail.com> wrote:

> I have
>
> ruleA: ruleB;
>
> ruleC: ruleB;
>
> ruleB: ruleD;
>
> In ruleB I want to different target language actions to execute  
> based on
> whether it was ruleA or ruleC that was previously matched.  If my
> understanding of syntatic/semantic predicates is correct, they only  
> look
> forwards, not backwards.
>
> Is there a way (without refactoring the grammar) to in rule B know  
> which
> rule it was invoked from (A or C) and make decisions accordingly?
>
> Thanks.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list