Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-core-dev] Compiler Extension

Guten Tag Herr Witten ;-)

> I want to add some features to the java compiler, including new java  
> syntax.
That's what we are doing for more than two years now: implementing
a Java-Extension on top of the JDT. 
(See http://www.objectteams.org for details).

My advice in a nutshell: do it (only) if you really know what you are doing.
There are Java compilers in the open source which are far easier
to adapt for new language features than the JDT (which is much more
than a compiler of course!).
If you choose to actually adapt/extend the JDT you will have to invest
significant efforts but you have the chance to get far more than just a
compiler for your language extension.
 
> Is there a plugin architecture for this?
No, the jdt-core is one (monolithic) plugin apparently not designed for 
adaptation. Plugin concepts mostly apply to building further plugins
ON-TOP of the jdt-core.
> Do I need to subclass existing classes?
Yes and no. You'll probably subclass some classes in the "ast" and
"lookup" packages. Using pure Java for the compiler implementation you 
will probably need to in-place modify a number of classes of the jdt compiler.
(It is our medium-term goal, to use our own language for non-invasive
adaptation of the JDT, please ask me for details if this is of interest for you)

> Do I need to rewrite existing classes?
Yes.

> which classes in particular? Parser/Compiler, .....
Certainly: Parser. While doing so, beware that there is not just one
Parser but also a number of subclasses thereof. Each one has to be
checked for needed adaptations as well.

Depending on the kind of extension you are planning,
everything else _could_ be handled in additional ast/binding classes.
For more comments I would need to know more about the language
you want to implement. (In our case about half the classes of the compiler
module had to be adapted, mainly because we added new type-checking).

Next you would have to check what other features beside the compiler
will need to be adapted (code completion, searching, refactoring to name
only a few). Depending on your answer to this question a number of
additional models will have to be extended, too.

All in all the whole project will probably only pay off if there's more than
one person involved.

> How best to express new grammars?
Learn LALR(1) and jikespg ;-)
(Another Caveat: one of the most tricky parts in the compiler seems to
be the section that deals with recovery from syntax errors (RecoveredElement
and subclasses, DiagnoseParser etc.). You won't become happy with the
compiler if you neglect this part)

regards
Stephan

--------------------------------------------------------------------------
 Dr. Stephan Herrmann
 ----------------
 Technische Universität Berlin
 Software Engineering Research Group
 http://swt.cs.tu-berlin.de/~stephan
 phone: ++49 30 314 73174         
--------------------------------------------------------------------------


Back to the top