[antlr-interest] Help needed upgrading java.g to support Generics

Pete Forman pete.forman at westerngeco.com
Fri Mar 14 02:42:18 PST 2003


At 2003-03-14 08:45 +1100, Matt Quail wrote:
>Thanks Monty! That has definitely given me something to think about. I 
>will try
>what you suggest, and remove the ">>", etc. tokens and parser them as GT GT
>instead.
>
>So we may have a parser rule:
>
>sr: GT GT;
>
>The one issue with this is that it will allow WS between the two ">" 
>characters
>in the ">>" operator (which Java does not allow). I might have a play with 
>this
>approach, in any case. I may be able to solve this problem by changing WS 
>from
>"skip" tokens to a {option ignore=WS;}. Will need to think some more on that
>one; any ideas?

An alternative to counting columns that I've used is to keep following
whitespace in the relevant token.  It can be tested in the parser and
removed if appropriate.

   GT: '>' (WHITESPACE)*;

Note that COMMENT might need to be included if that is also skipped.

A variation that I've not tried out is:

   GT: '>' { switch (LA(1)) {
             case '>': $setType(GT_PRE_GT); break;
             case '=': $setType(GT_PRE_EQ); break;
             }
           };

Which the parser might use as:

   unsigned_right_shift: expr1 GT_PRE_GT GT_PRE_GT GT expr2;

In other productions the GT might be (GT|GT_PRE_GT|GT_PRE_EQ).

-- 
Pete Forman                -./\.-  Disclaimer: This post is originated
WesternGeco                  -./\.-   by myself and does not represent
pete.forman at westerngeco.com    -./\.-   opinion of Schlumberger, Baker
http://petef.port5.com           -./\.-   Hughes or their divisions.


 

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



More information about the antlr-interest mailing list