[net.lang] C to Pascal translation.

bbl@amdcad.UUCP (BBL Software) (12/14/84)

I am trying to study the feasibility of writing a 'C' to Pascal 
translator and viceversa using YACC and LEX. I would like to 
know if someone has tried such an exercise. I would appreciate
comments on feasibility, issues involved and usefulness.
If I receive enough interesting responses, I will summarise it
on the net.
                            
			     


			     rajiv c. mody
              		     ..!amd!amdcad!bbl

chris@umcp-cs.UUCP (Chris Torek) (12/16/84)

In general, it cannot be done.  What would you do with

	union u {
		int (*f)();
		char *c;
	} u;

	h() {
		u.c = "foo";
	}

	g() {
		u.f = h;	/* Remember, I'm actually allowed to
				   make this assignment as complicated
				   as I want.  Maybe it depends on
				   input data.... */
	}

	main () {
		g();
		(*u.f)();
		printf("%s\n", u.c);
	}

If you make some restrictions, then it can sort of be done.
-- 
(This line accidently left nonblank.)

In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland

robert@gitpyr.UUCP (Robert Viduya) (12/18/84)

> 
> 	union u {
> 		int (*f)();
> 		char *c;
> 	} u;
> 	h() {
> 		u.c = "foo";
> 	}
> 	g() {
> 		u.f = h;
> 	}
> 	main () {
> 		g();
> 		(*u.f)();
> 		printf("%s\n", u.c);
> 	}
> 
> If you make some restrictions, then it can sort of be done.

Actually, the restriction is not in the unions.  Pascal can handle the
concept of unions by using variant records with no tag field specifier.
The restriction of translating C to Pascal is that Pascal does not support
pointers to functions.

			robert
-- 
Robert Viduya
Office of Computing Services
Georgia Institute of Technology, Atlanta GA 30332
Phone:  (404) 894-4669

...!{akgua,allegra,amd,hplabs,ihnp4,masscomp,ut-ngp}!gatech!gitpyr!robert
...!{rlgvax,sb1,uf-cgrl,unmvax,ut-sally}!gatech!gitpyr!robert

steve@hcradm.UUCP (Steve Pozgaj) (12/20/84)

Why bother trying to write one?  There are already several available.
Most notably [I wonder why I would say that?], HCR has a Pascal
compiler which front ends on the machine's C compiler.  It translates
Pascal source to C; it fully passes the Tasmanian Test Suite; and, it
is cheaper than doing it yourself.  To each his own, I suppose.

	Steve Pozgaj,
	Human Computing Resources
	Toronto

steve@hcradm.UUCP (Steve Pozgaj) (12/20/84)

Ooops!  Sorry about that brain-damaged response regarding HCR's
Pascal-to-C translator.  I was mesmerized by the falling snow
(honest!) and read the whole thing in the wrong direction!  I
promise to eat three fewer Christmas puddings as punishment.

	Steve Pozgaj,
	Human Computing Resources,
	Toronto

davet@oakhill.UUCP (Dave Trissel) (12/22/84)

<.......>
In article <437@gitpyr.UUCP> robert@gitpyr.UUCP (Robert Viduya) writes:
>> 
>> 	union u {
>> 		int (*f)();
>> 		char *c;
>> 	} u;
>> 	h() {
>> 		u.c = "foo";
>> 	}
>> 	g() {
>> 		u.f = h;
>> 	}
>> 	main () {
>> 		g();
>> 		(*u.f)();
>> 		printf("%s\n", u.c);
>> 	}
>> 
>> If you make some restrictions, then it can sort of be done.
>
>Actually, the restriction is not in the unions.  Pascal can handle the
>concept of unions by using variant records with no tag field specifier.
>The restriction of translating C to Pascal is that Pascal does not support
>pointers to functions.
>Robert Viduya

Modula-2 does.  Note that Modula-2 also handles string ala "C" with a zero
terminator byte.

Motorola Semiconductor                             Dave Trissel
Austin, Texas          {ihnp4,seismo,gatech,ctvax}!ut-sally!oakhill!davet

ken@rochester.UUCP (Ken Yap) (12/23/84)

In article <284@oakhill.UUCP> davet@oakhill.UUCP (Dave Trissel) writes:
>Modula-2 does.  Note that Modula-2 also handles string ala "C" with a zero
>terminator byte.

Not quite right. Modula-2 treats strings as arbitary length char
arrays.  This is normally implemented by passing two parameters, the
array address and a count.  The callee can find out how long the array
is by using the intrinsic HIGH(a) where a is the array in question.
Some implementations have chosen to add a null byte at the end as well
to allow intermixing of C and Modula-2 routines.

	Regards,
-- 
	Ken Yap

UUCP: (..!{allegra, decvax, seismo}!rochester!ken) ARPA: ken@rochester.arpa
USnail:	Dept. of Comp. Sci., U. of Rochester, NY 14627.