[antlr-interest] Re: Translating PASCAL (or C) into JAVA

jsrs701 jsrs701 at yahoo.com
Fri Feb 15 12:48:06 PST 2002

One of the previous posts on this subject made a good point, though--
what do you do about the whole pointer thing in Pascal (or C)?

Obviously, you'll need to have equivalent Java types for each Pascal 
type.  A Pascal "integer" would be a Java "int", a Pascal "record" 
would be a Java "class".

But what about them pesky pointers?

My suggestion would be to build a Java "pointer" class with certain 
operations (like dereference, which is spelled "^" in Pascal).  That 
makes the output Java code kinda weird looking, but it'll get the job 


--- In antlr-interest at y..., Terence Parr <parrt at j...> wrote:
> Hi Piet,
> 7 years ago, Gary Funck built a translator from an ancient language 
> the 60's similar to pascal to C if I remember.  As the others have 
> stated, there are issues with equivalency of languages, but you're 
> question is "can it be done."  Emphatically yes.  The ANTLR system 
> specifically designed to aid language translators (I built the tree 
> translator component to help me build 10 pass f-77 to parallel 
> translators back in the early 90s).
> So, it's just a matter of learning the tricks.  In most general 
terms it 
> can be summarized as follows:
> 1) Parse the old input file, constructing a tree representing the 
> structure of the input and constructing a symbol table (that may 
have to 
> be saved and used across parses/translations).
> 2) Manipulate the tree (intermediate form) in multiple passes using 
> tree grammar, slowing morphing it towards your target language.
> 3) When you think that your intermediate form is very close to the 
> target language then you can do a simple walk of the tree spitting 
> text again.  Each action in the grammar does a small bit of the 
work and 
> you pray that the emergent behavior results in valid output text. ;)
> I think i'll start a simple faq entry on this :)
> Terence
> --
> Chief Scientist & Co-founder, http://www.jguru.com
> Creator, ANTLR Parser Generator: http://www.antlr.org


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

More information about the antlr-interest mailing list