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

Andreas Rueckert a_rueckert at gmx.net
Thu Dec 6 01:09:27 PST 2001


On Mit, 05 Dez 2001 Terence Parr wrote:


> > But in all these cases, you used constants. Many fileformats come a 
> > counter,
> > that defines, how long the following data block is. So you have to 
> > parse the
> > counter 1st, and then match the next rule <counter> times.
> Oh, right.  Yeah not a problem at all except for syntax.  Should it 
> assume non-int implies variable defined in C++, Sather, or Java 
> (whatever your output is)?  I'm partial to keeping all non-grammatical 
> stuff in {...}.  Perhaps this then:
> ( ID )+{n=blockCount;}
> or something?

Since blockCount is a rule, I wouldn't really call it 'non-grammatical', but
other than that, it looks fine to me. But I'm really not a Antlr expert or so.
So I don't want to give you any recommendations. You're the guru in the house.

> > =======================================
> > rule
> > {int counter=0}
> > 	: counter=blockCount
> > 	  ( {counter>0}? blockEntry {counter--;} )*
> > 	;
> > =======================================
> > Do you think it would work? So that block entry is matched <counter> 
> > times?
> Let's see.  Well, it's close, but it wouldn't give you an error if you 
> have less than blockCount.  You need that "did I get enough" check at 
> the end of the loop.  Could do with a simple "validating" sem pred after 
> loop.

So I should add a { if{counter>0) {throw new RecognitionException(...);} }, or
so? Since I'm only reading bytes, the only case, where we 'didn't get enough',
is simply EOF.



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

More information about the antlr-interest mailing list