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

Sinan sinan.karasu at boeing.com
Wed Feb 20 11:36:07 PST 2002

pietschoutteten wrote:
> and I can build these together and test it with the example P_0_1.pas
> I also tested it with the grammer from Sinan (message 2398 Re: Ter,
> Would you mind looking at ....) which builds me an AST.

Wow, now if I could only remember what I've posted....

If you also search for f77 under the group, you'll get a f77.jar file.
( there are two versions. One of them is busted....)

That is the beginning of a f77 to java/whatever translator that I still 
wish to finish someday.


 I was a pascal programmer in a previous life ( way back in 80's...)

So from a cursory thinking point of view

XYZ x;

XYZ^ y;

can be treated identical and


can be both coded as 


with some caveats.....


 XYZ x;   ====>   XYZ x=new XYZ();
 XYZ y;   ====>   XYZ y;

 Then you can ignore all the ^ dereferencing.

Of course you must not have any illegal operations , such as

 x=new XYZ(); 

 anywhere else in the program, since now x is an immutable reference
where as y is not.
 This is not an issue for translation, however if anyone modifies the
later on, then bugs would creep in.

 VAR (IN/OUT) is problematic, since you could not have
 PROCEDURE P(XYZ ^^w:VAR) (syntax ???) and hope to modify ^w ( P(XYZ w)
, but you already know that...

b) Go to goole and search for 'taming goto'
 The paper describes how one can get rid of goto statements.

 Then your translator would consist of a parser (tree generator)
 and possibly multiple treewalkers.

 I don't know what the status of tree transformation is in 2.7.2.
In 2.7.1 you had to do a dupe() on the tree before you could modify it
append it to the one you were building.

 So in the end , you do a translated source code emit ( with
postfix expressions becoming infix ).

 Postfix to infix conversion requires a little housekeeping about
the precedence rules. Otherwise

 a= 1*2 ;
 translates into a=(1)*(2);
 which translates into a=((1))*((2)); so on if you are not careful
about additive/multiplicative/etc... precedence.

Enough blither....



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

More information about the antlr-interest mailing list