[antlr-interest] Anything wrong with LT(-1); ? I want to get the previous token.

charlweed charlweed at yahoo.com
Mon Aug 9 15:43:17 PDT 2004


I think I merely want to know what the PREVIOUS token actually was, so
I can rewrite the stream. I tries LT(-1) and I was surprized that it
seemed to work!
However, is this a Bad Idea? I'm I going to run into some odd bugs by
using negitive arguments?

I want ther previous token because I want to replace an identifier
with a getter. However, if the identifier is the operand of a
decrement or increment unary operator, I want to leave it alone:

j = _i ;// becomes j = getI();
_i++; // stays the same. Easy to detect, just look ahead.
--_i; // stays the same. I need to look back to see if the previous
Token is an INC or DEC

The easiest place to put my re-write method is within the identPrimary
rule. But at that point, I need to know if the previous token was an
INC or DEC and must therefore be unmodified. If I add a re-write
method within the rule for pre-increment or decrement, then I need
lots of logic to enable and disable the rewrite at identPrimary.




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list