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

mzukowski at yci.com mzukowski at yci.com
Thu Mar 13 16:05:31 PST 2003


That looks pretty good to me.  I would've used (typeArgumentsEnd)? in
typeArguments instead of having the nothing match inside typeArgumentsEnd,
but I think the difference is minimal.

Monty

-----Original Message-----
From: Matt Quail [mailto:matt at cortexebusiness.com.au]
Sent: Thursday, March 13, 2003 3:18 PM
To: antlr-interest at yahoogroups.com
Subject: Re: [antlr-interest] Help needed upgrading java.g to support
Gene rics


> The semantic predicate is a good possible approach.

Okay, I've tried the semantic predicate approach, this is what I have:

referenceType
     :
         identifier
         (  arrayDecl
         |  typeArguments
         )?
     ;

typeArguments:
         {int currentLtLevel = ltCounter;}
         LT {ltCounter++;}
         referenceType
         (
             COMMA referenceType
         )*
         typeArgumentsEnd
         {(currentLtLevel != 0) || ltCounter == currentLtLevel}?
     ;
typeArgumentsEnd:
         GT {ltCounter-=1;}
     |   SR {ltCounter-=2;}
     |   BSR {ltCounter-=3;}
     |


Things to note:
- this grammar now handles lists of arguments like <String,Integer>
- this grammar compiles with nondeterminism warnings, I'm not sure
   if they are ignorable yet.
- typeArguments ends in a "validating" semantic predicate, that
   ensures that if there was a zero 'LT' count upon entry, then it
   is zero upon exit. So it allows the LT count to cross "nested
   boundries".
- typeArgumentsEnd may match nothing. But it must match eventually
   because of the validating sematnic predicate in typeArguments

I'll play with it further, but I think this semantic-predicate approach may
be 
the easiest way forward.

=Matt


 

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


 

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



More information about the antlr-interest mailing list