[antlr-interest] [ANTLRWorks 1.4][Code Generation] [C target] Bug??

Jim Idle jimi at temporal-wave.com
Wed Dec 1 11:13:18 PST 2010


Actually you want to just stop trying to enforce this using syntax and
specify the semantic rules in actions or better still in a tree walk.

So just set flags to say which things you find and check the state to see if
they are illegal. But besides that this is surely:

rule1: (rule2 (a | b)*)*;  

With a check to see that if there are any illegal combinations.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Kevin J. Cummings
> Sent: Wednesday, December 01, 2010 8:21 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] [ANTLRWorks 1.4][Code Generation] [C
> target] Bug??
> 
> On 12/01/2010 10:32 AM, Amr Muhammad wrote:
> > Hello,
> >
> > I have a rule like this:
> >
> > version1 ---  rule1: (rule2 (a+ b* | b* a+) )* (rule2 a*)*
>                        ^^^^^^^^^^^^^^^^^^^^^^^^^ Hmmm, 1 or more a
> followed by 0 or more b OR zero or more b followed by
> 1 or more a.
> 
> What happens when there are 0 b.  Your code reduces to 1 or more a OR 1
> or more a.
> 
> I would re-write this as:
> 
> rule1: (rule2 ( (a+ b*) | (b+ a+)) )* (rule2 a*)*
> 
> as the case of just matching a+ is handled by the first alternative.
> 
> Now you need to handle the problem of the which rule2 case to match
> given that the first one could be empty and you want to match the
> second.  I think you need to disambiguate your grammar further.
> 
> --
> Kevin J. Cummings
> kjchome at rcn.com
> cummings at kjchome.homeip.net
> cummings at kjc386.framingham.ma.us
> Registered Linux User #1232 (http://counter.li.org)
> 
> 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