[antlr-interest] Please help with a grammar issue

Indhu Bharathi indhu.b at s7software.com
Fri Oct 30 09:36:06 PDT 2009


Maybe you can use validating semantic predicate

 

r              

@init {

                int cntA=0, cntB=0, cntC=0;

}

                :               ( a {cntA++;} | b {cntB++;} | c {cntC++;} )+ {cntA>1 && cntB<=1 && cntC==1}?

                ;

 

Cheers, Indhu

S7 Software

 

 

From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Frank Du
Sent: Friday, October 30, 2009 9:53 PM
To: 'antlr-interest at antlr.org'
Subject: [antlr-interest] Please help with a grammar issue

 

Dear All,

 

I have a grammar issue and need your help. Let’s say I have tree rules: a, b, c

 

Rule a occurs multiple times, rule b occurs one time or none, and rule c occurs one time.

 

My question is: How to write the grammar, so the rule ordering is arbitrary? 

 

Thank you so much! Have a nice day!

 

Best Regards,

Frank

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091030/c8267bea/attachment.html 


More information about the antlr-interest mailing list