Hi Indhu,

Thank you so much for the code. I was using ANTLRWorks and exception was 
handle. Yes, it works now!

Thanks,
Frank
-----Original Message-----
From: Indhu Bharathi [mailto:[email protected]] 
Sent: Friday, October 30, 2009 1:28 PM
To: Frank Du; [email protected]
Subject: RE: [antlr-interest] Please help with a grammar issue

When I give 2 'b', I get parser error.

Here is the complete grammar I used:

grammar Test;

r
@init {
                int cntA=0, cntB=0, cntC=0; 
}
                :               ( a {cntA++;} | b {cntB++;} | c {cntC++;} )+
{cntA>1 && cntB<=1 && cntC==1}?
                ;

a       :       'A'
        ;
        
b       :       'B'
        ;
        
c       :       'C'
        ;

And my test input was: "ABBC". Parser will throw failed predicate exception
on this input.

Can you give a compilable small grammar where it doesn't work and also the
input you tried?


Cheers, Indhu
S7 Software


-----Original Message-----
From: Frank Du [mailto:[email protected]] 
Sent: Friday, October 30, 2009 10:38 PM
To: Indhu Bharathi; [email protected]
Subject: RE: [antlr-interest] Please help with a grammar issue

Hi Indhu,

Thank you so much! It works pretty well on correct input file. 

However, if I have 2 rules of b, the parser will stop at the second. It
doesn't emit errors as expected. Then it hinders from validation. Any idea
about that?

Cheers,
Frank

________________________________________
From: Indhu Bharathi [[email protected]]
Sent: Friday, October 30, 2009 12:36 PM
To: Frank Du; [email protected]
Subject: RE: [antlr-interest] Please help with a grammar issue

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: [email protected]
[mailto:[email protected]] On Behalf Of Frank Du
Sent: Friday, October 30, 2009 9:53 PM
To: '[email protected]'
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


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
-~----------~----~----~----~------~----~------~--~---

Reply via email to