Hi Achint,
Maybe something like:
first
@init { bool second_rule_matched = false; }
: (second)? { second_rule_matched = true; } third
{
if(second_rule_matched)
cout<<" Second rule matched"<<endl;
}
;
Or p. 126 of the Antlr book describes how to do it with optional tokens,
something like (assuming 'second' is a token):
first
: (second_rule_matched='second')? third
{
if($second_rule_matched != 0)
cout<<" Second rule matched"<<endl;
}
;
Regards, Mark
On Fri, 21 Aug 2009 23:34:05 -0400
Achint Mehta <[email protected]> wrote:
> Hi All,
>
> If I have a option rule in my grammar, how can I check whether that rule
> matched or not.
> e.g. if I have a rule in my grammar
>
> first: (second)? third
> {
> if(/* second rule matched */)
> cout<<" Second rule matched"<<endl;
> }
>
> How do I write the if condition (in C/C++) ? (I am using version 3.1.3 of
> the antlr)
>
> Thanks!
>
> Regards,
> Achint
--
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---