[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Java compiler implementation in SableCC needed.



Hi,

We implemented an extended Java syntax using multiple different tools (the reasons why we did multiple implementations I won't go into...) so we are probably uniquely placed to answer this question.

In SableCC we implemented a pre-processor that took the extended syntax java and spat out plain java that javac could process.  We integrated it into the tools fairly transparently so you could invoke the tool just like javac.  It is   not fast and quite memory hungry, but does the job.  The biggest difficulties were in correctly preserving indentation and commenting and getting error messages to report the correct source line numbers.

The approach reasonably easy because the example Java parser just re-outputs the code that it parses (you need to add a custom lexer to preserve whitespace if you don't want it to all be on one line!).

An approach that yeilded much quicker results was to use a proprocessor tool called EPP.  It has a steeper learning curve than SableCC but did yeild results much faster for this particular application.  This should be what you choose.

http://staff.aist.go.jp/y-ichisugi/epp

A place where you can find many interesting extended java projects is

http://grunge.cs.tu-berlin.de/~tolk/vmlanguages.html

which is where we found epp.  Thirdly we implemented a modified version of the compiler that comes with the Eclipse IDE platform (www.eclipse.org).  This was more difficult, but is much faster and better integrated than the above two approaches.  

Lastly you could (although we stopped at three implementations!) try modifying the experimental compiler that comes as part of the demonstration for adding Generics to Java that Sun is making available for download (generics will be in Java 1.5).  It comes with source code (unusually readable for Sun too).  

I hope that helps.  I'm not trying to suggest that you shouldn't use SableCC - I completely love it, but you might get quicker results using EPP because its a tool more specifically targetted at Java syntax.

Regards

Jim
--
Dr James Moores, Director, Quickstone Technoloiges Limited, UK.


-----Original Message-----
From:	Qi Sun [mailto:qsun@stevens-tech.edu]
Sent:	Fri 17/01/2003 18:32
To:	sablecc-list@sable.mcgill.ca
Cc:	
Subject:	Java compiler implementation in SableCC needed.
Thank you for efforts on sablecc. It is great.

I am now trying to extend java syntax. In addition to lex/parsing, I need
a function that can inference types for Java expressions statically. I
guess the easiest way to do it is to find a java compiler implementation
based on sablecc. Does any one has any idea? In fact, I need no more than
inferencing the expression. I am afriad of writing a tools that people may
have already done a lot.

Any suggestion or hints are welcomed. Thank you.

--River.