'C' to PASCAL translator 
Author Message
 'C' to PASCAL translator

I've been looking for a *modern* C to Pascal translator and have only
found pascal to c. Any help in locating this is very appreciated!!

I have found a very old (circa 88) translator but would like a more
recent program. Or will I just have to learn C to be able to translate?

Jeff



Wed, 18 Jun 1902 08:00:00 GMT  
 'C' to PASCAL translator

Quote:

>I've been looking for a *modern* C to Pascal translator and have only
>found pascal to c. Any help in locating this is very appreciated!!

>I have found a very old (circa 88) translator but would like a more
>recent program. Or will I just have to learn C to be able to
translate?

>Jeff

Really! where did you get the C to Pascal translator?


Wed, 18 Jun 1902 08:00:00 GMT  
 'C' to PASCAL translator
I would like to know where you found a Pascal to C translator.  I've been
looking for one for hours.


Wed, 18 Jun 1902 08:00:00 GMT  
 'C' to PASCAL translator

Quote:


>>I've been looking for a *modern* C to Pascal translator and have only
>>found pascal to c. Any help in locating this is very appreciated!!

>>I have found a very old (circa 88) translator but would like a more
>>recent program. Or will I just have to learn C to be able to
>translate?

>>Jeff
>Really! where did you get the C to Pascal translator?

Well, I can help you guys out a lot.  I can give you some basics on
manually translating....

1) In C, everything is a function, including the main group.  The main
program MUST be a function called MAIN.

2) The layout of a function is such as this:
        If in Pascal, we have a function named: function add2numbers(a, b:
        integer):integer; in C it would be int add2numbers(int a, b)

        When something returns or accepts nothing....such as a pascal
        procedure, it is set up like a function except for the return, which
        is referred to as void.  So procedure add2numbers(a, b, answer:
        integer); would be void add2numbers(int a,b,answer);

3) reads and writes are done via printf and scanf.  Look those up in
the online help for your compiler.  header files are the equivalent of
unit files in Pascal, and to do these, you need to use the statement:

#include <stdio.h>

4) Arithmetic operators.
        in C = replaces := and == replaces =.
        in C * replaces MOD.

5) Increments and decrements can be done via ++ and -- on a variable.

6) while i < 10 do in Pascal would become while (i < 10) in C.

7) for i := 1 to 10 in Pascal would become for (i = 1;i <10; i++)

8) Begin is replaced with { while end is replaced with }.

9) to declare variables.
   int a is equivalent to var a: integer;
   char a is equivalent to  var a: char;
   int a[32] is equivalent to var a: array[0..31] of integer;

This stuff should be a thumbnail sketch -- enough to allow you to
understand most of what goes on with elementary C programs to
translate them to Pascal.  If it's anything else, I recommend you look
them up.

Glenn Grotzinger

MOD and S3M user extraordinaire.
Writer of TP tutorial.  All released parts findable at:
ftp://garbo.uwasa.fi/pc/turbopas/tptutr11.zip



Wed, 18 Jun 1902 08:00:00 GMT  
 'C' to PASCAL translator


Quote:
> I would like to know where you found a Pascal to C translator.  I've been
> looking for one for hours.

I have one that is a filename called CTOP12B.ZIP (all lower case).   It
has two C programs in it that it can convert somewhat errorfree.  
Although I do find that it could use many more additions (like modified
removal of comments, and it doesn't seem to like any IF compiling source).


Wed, 18 Jun 1902 08:00:00 GMT  
 'C' to PASCAL translator

Quote:

> 1) In C, everything is a function, including the main group.  The main
> program MUST be a function called MAIN.

> 2) The layout of a function is such as this:
>         If in Pascal, we have a function named: function add2numbers(a, b:
>         integer):integer; in C it would be int add2numbers(int a, b)

>         When something returns or accepts nothing....such as a pascal
>         procedure, it is set up like a function except for the return, which
>         is referred to as void.  So procedure add2numbers(a, b, answer:
>         integer); would be void add2numbers(int a,b,answer);

Also you can put void as the parameter list for a function which accepts no
parameters

Quote:
> 3) reads and writes are done via printf and scanf.  Look those up in

scanf is not really very useful.  fgets() {NEVER USE gets()} and string
functions are infinitely preferable.  fgets() is similar to readln(astring);

Quote:
> the online help for your compiler.  header files are the equivalent of
> unit files in Pascal, and to do these, you need to use the statement:

> #include <stdio.h>

> 4) Arithmetic operators.
>         in C = replaces := and == replaces =.
>         in C * replaces MOD.

That should be a percent sign for mod `%'.

Quote:
> 5) Increments and decrements can be done via ++ and -- on a variable.

Note that this can happen in an expression.  eg:

int i=3;
int j;

j=i++;  /* j becomes 3, i becomes 4 */
j=++i;  /* j now becomes 5, i becomes 5 */

Note the differences in order of evaluation.

Quote:
> 6) while i < 10 do in Pascal would become while (i < 10) in C.

> 7) for i := 1 to 10 in Pascal would become for (i = 1;i <10; i++)

> 8) Begin is replaced with { while end is replaced with }.

> 9) to declare variables.
>    int a is equivalent to var a: integer;
>    char a is equivalent to  var a: char;
>    int a[32] is equivalent to var a: array[0..31] of integer;

Note especially pointer differences:

int *x;
is a pointer to an integer.
y=*x;
dereferences the pointer.  (Note that here *x is uninitialised!)

As well as that strings are PChars!

Again, you need good documentation on the language to get anywhere.  On-line
help will guide you (slowly :) through the function calls.

If you are at all serious about learning C, then get `The C Programming
Language' by K&R.  It's small and expensive, but definitive.

.splitbung, who uses C for portability, but still thinks in TP :)
--
* TQ 1.0 * The 'Just So Quotes'.
"Strange women lying in ponds distributing swords is no basis for a system of
 government! Supreme executive power is derived by a mandate from the masses,
 not from some farcical aquatic ceremony!"



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. The world's foremost FORTRAN to C Translator

2. type field ''money''

3. IndexDefs.Add('Help','Please',[ixD2WorksGreat, ixD3Errors])

4. Pascal to 'C' FAQ

5. Looking for equivalent to 'friend'(C++) in object pascal

6. TmT Pascal Lite question 'Speed Bumps'

7. Playing CD's or MIDI's in pascal

8. 'Bitfields' in Pascal

9. Playing AVI's and WAV's Through Turbo Pascal

10. pascal 'real' data to vb 'double'

11. 'Incompatible types 'string' and 'Tdbedit''

12. Replace 'keystack''

 

 
Powered by phpBB® Forum Software