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

Matt Quail matt at cortexebusiness.com.au
Thu Mar 13 15:18:25 PST 2003


> 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/ 



More information about the antlr-interest mailing list