[antlr-interest] Re: Antlr grammar to parse Java classfile?

mzukowski at bco.com mzukowski at bco.com
Thu Dec 6 07:02:10 PST 2001


You are right, semantic predicates are ignored if you are guessing.  That's
a gotcha that could be taken care of only by extending antlr or extremely
ugly and unmaintainable syntactic predicates.

Hopefully for the java classfile format there should be no guessing...but
this isn't a general solution to the "match n times" problem.

Monty

> -----Original Message-----
> From: Ric Klaren [mailto:klaren at cs.utwente.nl]
> Sent: Thursday, December 06, 2001 1:47 AM
> To: antlr-interest at yahoogroups.com
> Subject: Re: [antlr-interest] Re: Antlr grammar to parse Java 
> classfile?
> 
> 
> Hi,
> 
> On Wed, Dec 05, 2001 at 02:53:56PM -0800, mzukowski at bco.com wrote:
> > > rule
> > > {int counter=0}
> > > 	: counter=blockCount 
> > > 	  ( {counter>0}? blockEntry {counter--;} )*
> > > 	;
> > > =======================================
> > > Do you think it would work? So that block entry is matched 
> > > <counter> times?
> > 
> > That generates this code:
> > 
> > 		int counter=0
> > 		
> > 		try {      // for error handling
> > 			counter=blockCount();
> > 			{
> > 			_loop3:
> > 			do {
> > 				if (((LA(1)==LITERAL_A))&&(counter>0)) {
> > 					blockEntry();
> > 					counter--;
> > 				}
> > 				else {
> > 					break _loop3;
> > 				}
> > 				
> > 			} while (true);
> > 			}
> > 		}
> > 		...
> > 
> > Looks like it will work to me.
> 
> Not 100% sure so of the top of my head... but if the rule is invoked
> somewhere in the path of a syntactic predicate will it work 
> as well? E.g.
> if guessing > 0 ?
> 
> I have some vague recollection of these things biting in some cases.

 

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



More information about the antlr-interest mailing list