At 00:39 17/10/2009, Naveen Chawla wrote:
>So, does anybody have a way of doing "Take *a* IF not followed by 
>*b* (both syntactic constructs)" ?
>
>i.e.
>q: (a !b)=> a;                        //("!" or "not" doesn't 
>exist in ANTLR)

Actually there is a negation operator, ~ -- but this operates on 
sets, not on sequences.  So in the lexer you can use "any single 
character not in this set" and in the parser you can use "any 
single token not in this set", but you can't get it to match on 
longer sequences without splitting them up into single-char/token 
decisions.

Without knowing more about what your a and b are, it's hard to 
give any more specific advice; for example, if b is a fixed 
sequence, such as DOT STAR, then you can do the above like so:

q : (a (~DOT | DOT ~STAR)) => a
   | /* nothing */
   ;

(I'm fairly sure you have to explicitly provide an alternative, 
either explicitly like this or via ?; if you don't then I think 
ANTLR will discard the predicate.  With no alternatives a 
predicate is useless.)

If b is not a fixed sequence, then you still need to provide the 
alternative choice, but by reversing the predicate:

q : (a b) => /* nothing */
   | a
   ;

Note that I haven't actually tested either of these, but in 
principle they ought to work. :)


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