[antlr-interest] Re: Antlr grammar to parse Java classfile?
Andreas Rueckert
a_rueckert at gmx.net
Wed Dec 5 00:11:55 PST 2001
Hi!
On Mit, 05 Dez 2001 J. Stephen Riley Silber wrote:
--<snip>--
> > I know that predicates are one of the features ANTLR has. I think
> this could
> > be the only salvation...
>
> Symantic predicates would indeed handle the "match n-times" problem.
Antlr turns every rule into a method, right? And you could call such a method
in a production? Why not do something like
=======================================
// Parse the method block in the classfile
methods
{ int mCount = 0; }
: mCount = methodCount
{ for( int i=0; i < mCount; i++) { method(); } }
;
// Parse one method in the classfile
method
: ....
=======================================
, where methodCount returns the number of methods in the classfile and
the method rule parses a method in the classfile. Then construct a nice AST, so
the tree grammar could be really clean.
> The thing is, and sorry Terry--nothing personal, I just don't think
> ANTLR is really the right tool for this kind of thing.
I agree, that the 'call the method rule n times' option is missing somehow. It
would make the creation of binary parsers somewhat easier.
> Building the .class file parser in any language with decent byte and
> bit analysis constructs is gonna be easy--tedious, definitely, but
> pretty easy.
>
> The real advantage of building a parser in ANTLR is when you have to
> *change* the parser. And in this case, for something so binary, I
> think changing the ANTLR parser vs. changing a C parser (for example)
> would end up being a wash.
Well, data abstraction also has the advantage of being more readable, than a
coded parser. And if you have all basic types, like u2, u4 etc. defined, you
could basically retype the classfile definition from the JVM specs to write the
parser.
classfile
: magic_number
version_number
constant_pool
access_flags
this_class
super_class
...
> Of course, I might be way off base here. :-)
>
> In any event, I still think ANTLR is the best thing going in the
> parser-generator world, by far!
I agree. And I've used lex,yacc,JavaCC etc.
Ciao,
Andreas
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list