Yikes, that doesn't seem to work, it seems to give a normal positive predicate for me. (Or something). But not "if a not followed by b" => a.
? 2009/10/14 Indhu Bharathi <[email protected]> > The other say I replied from my ipod and was not able to test it with > ANTLR. I checked it now and the code doesn’t work for me too. However you > can try a variant: > > > > q : a ((b)=>NOWAY | /*nothing*/) > > ; > > > > fragment NOWAY > > : ; > > > > This is tested J But note that this is only a hack and use it only when > there is no other alternative. > > > > Going by your “one of my "smaller" rules is "consuming" something that > should belong to a "larger" rule” description, it looks like you can solve > that problem by turning off greedy. Grep for ‘greedy’ in the book or wiki. > > > > Cheers, Indhu > > > > > > *From:* [email protected] [mailto: > [email protected]] *On Behalf Of *Naveen Chawla > *Sent:* Wednesday, October 14, 2009 3:50 PM > *To:* Jim Idle > *Cc:* [email protected] > *Subject:* Re: [antlr-interest] How to do "not" in a syntactic predicate? > > > > Jim, being new to predicates I realised soon after this that you were > talking about token lookaheads. And yes I do need a syntactic lookahead (but > thas is negative). In beginner-speak, one of my "smaller" rules is > "consuming" something that should belong to a "larger" rule. This would be > correct if that particular something (e.g. "a") was *not* followed by a > syntactic construct conforming to "b". Hence (a !b)=>a (for the smaller > rule) seems the simplest solution to this to me. Is Indhu's version correct > for doing this trick? It doesn't seem to work for me (but I might be doing > something else wrong). If not correct, what is the correct way? My target is > Java. > > 2009/10/5 Jim Idle <[email protected]> > > Use a semantic predicate rather than syntactic. You possibly need a bated > predicate here too: > > > > { input.LA(1) == A && input.LA(2) != B}?=> > > > > However, if you need that kind of syntactic predicate, then I suggest you > may be approaching your problem incorrectly. > > > > Jim > > > > *From:* [email protected] [mailto: > [email protected]] *On Behalf Of *Naveen Chawla > *Sent:* Monday, October 05, 2009 7:02 AM > > > *To:* [email protected] > *Subject:* [antlr-interest] How to do "not" in a syntactic predicate? > > > > If I do > > > > (a ~b)=> a > > > > meaning "take this alternative if you encounter an a when not followed by > b" > > > > I get a syntax error: unexpected token b > > Is it the right syntax to use '~'? > > > > N > > > > 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 -~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
