Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [jdt-core-dev] Eclipse-conformant parser generator?

Interesting idea... Probably more of a general eclipse core concept rather
than just a jdt concept, though.

ANTLR has pluggable code generators (which can be subclassed -- I've done
that in the past when I integrated it into VAJ). Overall this shouldn't be
hard to do.

Of course, there's a learning curve associated with tools like ANTLR, mainly
getting in the mindset of declarative programming via a grammar. I've got an
old ANTLR tutorial at http://javadude.com/articles that's a good start, but
it really comes down to mindset. But if you have to write a parser anyway,
much better to write one using a generator (IMHO).

To make it easier, I'd recommend that we look to ANTLR's automatic AST
generation capabilities. I haven't tried overriding these in ANTLR, but I
did it for PCCTS, ANTLR's precursor, quite easily. Should be pretty easy
with ANTLR as well. If I recall, ANTLR has some factories for creating the
nodes.

For example, a structure like the following (off the top of my head) in a
grammar

    FOR^ LPAREN! (initExpr)? SEMI!
                 (testExpr)? SEMI!
                 (updateExpr)?
         RPAREN! 

would automatically create an AST as follows:
1) throw out the LPAREN, RPAREN and SEMIs (the "!" says "don't include in
AST")
2) promote the FOR to be the current parent node (the "^" says "promote me")
3) add the subtrees generated by initExpr, testExpr and updateExpr to the
current parent node

These concepts should be compatible with any AST implementation; it's just a
matter of determining which objects to create for the nodes and how to
connect them.

ANTLR.org is down right now, so I wasn't able to take a peek at the
generator code to see how easy this would be to do.


Further, once the ASTs exist, it might also be interesting to create a tree
walker for the resulting ASTs. ANTLR has tree-walker grammars, but they're
based on ANTLR tree structures. I'm pretty sure it could be adapted pretty
easily into reading other tree structures, such as ASTs in Ecilpse.

- Scott

(BTW: I used to work for Terence Parr, ANTLR's creator, and I wrote the
ParseView debugger for it. One of these days I need to update and integrate
the debugger with eclipse. Ter loves eclipse, too...)

> -----Original Message-----
> From: jdt-core-dev-admin@xxxxxxxxxxx 
> [mailto:jdt-core-dev-admin@xxxxxxxxxxx] On Behalf Of Eric Bodden
> Sent: Wednesday, January 21, 2004 9:26 AM
> To: jdt-core-dev@xxxxxxxxxxx
> Subject: [jdt-core-dev] Eclipse-conformant parser generator?
> 
> Hello!
> 
> I was just thinking about how the actual build process for 
> the building the Java model works at the moment. Were all 
> these classes coded by hand or do/did people any parser 
> generators in order to build them?
> 
> I am just asking because I think it would be a great 
> strategic advantage vor Eclipse over other IDEs if somebody 
> had a tool could generate for any given input grammar a an 
> appropriate parser / AST that is automatically 
> Eclipse-conformant meaning it would conform to conding 
> standards, automatically subclass / implement necessary 
> superclasses / interfaces etc. I believe that would make 
> thinks like e.g. the current development of the C++ model or 
> AspectJ model much easier.
> 
> I think i general such a tool should not be too difficult to 
> develop if somebody used ANTLR or something like that.
> 
> What do people think about that?
> 
> Eric Bodden
> --
> www.bodden.de
> 
> 
> _______________________________________________
> jdt-core-dev mailing list
> jdt-core-dev@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/jdt-core-dev
> 
> 
> 




Back to the top