Category : Pascal Source Code
Archive   : TPTC17.ZIP
Filename : TPTC.DOC

 
Output of file : TPTC.DOC contained in archive : TPTC17.ZIP


TPTC16 - Translate Pascal to C
Version 1.6, 13-Feb-88

(C) Copyright 1986, 1988 by Samuel H. Smith
All rights reserved.


This program will read a turbo pascal source file and convert it into
the corresponding C source code. It does much of the work required in
a full translation.

Usage: TPTC input_file [output_file] [options]

Where: input_file specifies the main source file, .PAS default
output_file specifies the output file, .C default
-B deBug trace during scan
-BP deBug trace during Parse
-D Dump user symbols
-DP Dump Predefined system symbols
-I output Include files' contents
-L map all identifiers to Lower case
-M use Pascal/MT+ specific translations
-NC No Comments passed to output file

-Q Quiet mode; suppress warnings
-Sdir\ search dir\ for .UNS symbol files
-Tnn Tab nn columns in declarations
-Wdrive: use drive: for Work/scratch files (ramdrive)
-# don't translate lines starting with "#"

Default command parameters are loaded from TPTC environment variable.

Example: tptc fmap
tptc fmap -L -d -wj:\tmp\
tptc -l -d -wj: -i -q -t15 fmap.pas fmap.out

set tptc=-wj: -i -l -sc:\libs
tptc test ;uses options specified earlier


LICENSE
=======

SourceWare: What is it?
-----------------------
SourceWare is my name for a unique concept in user supported software.

Programs distributed under the SourceWare concept always offer complete
source code.

This package can be freely distributed so long as it is not modified
or sold for profit. If you find that this program is valuable, you
can send me a donation for what you think it is worth. I suggest
about $20.

Send your contributions to:
Samuel. H. Smith
5119 N. 11 ave 332
Phoenix, Az 85013


Why SourceWare?
---------------
Why do I include source code? Why isn't the donation manditory? The
value of good software should be self-evident. The source code is
the key to complete understanding of a program. You can read it to
find out how things are done. You can also change it to suit your
needs, so long as you do not distribute the modified version without
my consent.


Copyright
---------
If you modify this program, I would appreciate a copy of the new
source code. I am holding the copyright on the source code, so
please don't delete my name from the program files or from the
documentation.


SUPPORT
=======

I work very hard to produce a software package of the highest
quality and functionality. I try to look into all reported bugs, and
will generally fix reported problems within a few days.

Since this is user supported software under the SourceWare concept,
I don't expect you to contribute if you don't like it or if it
doesn't meet your needs.

If you have any questions, bugs, or suggestions, please contact me
at: The Tool Shop BBS (602) 279-2673

The latest version is always available for downloading.

Enjoy! Samuel H. Smith
Author and Sysop of The Tool Shop.




The following language constructs are translated:
------------------------------------------------

Comments are translated from either {...} or (*...*) into /*...*/.

Begin and End are translated into { and }.

Const declarations are translated from
ID = VALUE
into
static ID = VALUE.

Simple Var declarations are translated from
ID TYPE
into
TYPE ID.

Integer subrange types are translated into integers.

Record types are translated from
ID = record MEMBER-LIST end
into
typedef struct { MEMBER-LIST } ID.

Enumeration types are translated from
ID = (...)
into
typedef enum {...} ID.

Array types are translated from
ID = array [RANGE] of TYPE
into
typedef TYPE ID[RANGE].

Pointer types are translated from
ID = ^DEFINED-TYPE
into
DEFINED-TYPE *ID.

String types are translated from
ID = string[N]
into
typedef char ID[N+1].

File types are translated from
ID = text[N]
ID = file
into
FILE *ID
int ID.

For statements are translated from
for VAR := FIRST to LAST do STATEMENT
for VAR := FIRST downto LAST do statement
into
for (VAR = FIRST; VAR <= LAST; VAR++) STATEMENT
for (VAR = FIRST; VAR >= LAST; VAR--) STATEMENT

While statements are translated from
while COND do STATEMENT
into
while (COND) statement.

Repeat statements are translated from
repeat STATEMENTS until COND
into
do { STATEMENTS } while(!COND).

If statements are translated from
if COND then STATEMENT else STATEMENT
into
if (COND) STATEMENT; else STATEMENT.

Case statements are translated from
case VALUE of
V: STATEMENT;
V,U: STATEMENT;
else STATEMENT
end
into
switch (VALUE) {
case V: STATEMENT; break;
case V:
case U: STATEMENT; break;
default: STATEMENT;
}.

Ranges in the form VAL..VAL automatically include cases for
intermediate values.

The IN operator is translated from
VAL in [A,B,C]
into
inset(VAL, setof(A,B,C,-1)).

The ParamCount and ParamStr functions are translated from
paramcount
paramstr(n)
into
argc
argv[n].

Dummy parameter lists are added to function and procedure calls,
where they are required in C but not in Pascal.

The following expression operators are translated
from DIV to / , MOD to % ,
AND to &&, OR to ||,
XOR to ~ , <> to !=,
NOT to ! , SHR to >>,
SHL to <<, = to ==, {+others}
:= to = .
Bitwise AND and OR operators are translated into & and |.

The '^' symbol is translated
from VAR^ to *VAR,
VAR^.MEMBER to VAR->MEMBER.

Exit statements are translated
from exit to return.

The New operator is translated from
new(VAR)
into
VAR = malloc(sizeof(*VAR)).


Procedure/function formal parameter lists are translated into the
new form defined in ANSI C (and as used by Turbo C):
from
function NAME(V1: TYPE1; V2: TYPE2): TYPE3
into
TYPE3 NAME(TYPE1 V1,TYPE2 V2)

Procedures are translated into functions with 'void' return types.

The special character literal syntax, ^C or #nn, is translated into

'\ooo', where ooo is the octal notation for the ascii code.

Hex constants $hhhh are translated into 0xhhhh.

Write and WriteLn are translated from:
write(VAR,VAR:n,VAR:n:m)
writeln(FILE,VAR,VAR,VAR)
into
printf("%d%nd%n.md",VAR,VAR,VAR)
fprintf(FILE,"%d%d%d\n",VAR,VAR,VAR).

Read and ReadLn are translated from:
read(VAR,VAR,VAR)
readln(FILE,VAR,VAR,VAR)
into
scanf("%d%nd%d",&VAR,&VAR,&VAR)
fscanf(FILE,"%d%d%d\n",&VAR,&VAR,&VAR).

String assignments are translated from:
VAR := "string"
VAR := "string1(" + VAR1 + ")string2"
into
strcpy(VAR, "string")
sbld(VAR,"string1(%s)string2",VAR1). {+other compound forms}

String comparisons are translated from:
VAR == "string"
VAR < "string"
"string" >= VAR
into
(strcmp(VAR,"string") == 0)
(strcmp(VAR,"string") < 0)
(strcmp("string",VAR) >= 0).

Function value assignments are translated from:

FUN_NAME := expr
into
return expr.

Numeric statement labels are translated to label_nn.
Label identifiers are not changed.
Local GOTO statements are handled properly.

Nested procedures are "flattened" out, but local variable sharing and
local scoping are not translated.

Direct I/O port and memory references are translated:
portw[expr] := expr + port[n]
mem[seg:ofs] := memw[seg:ofs] + expr
into
outport(expr, expr+inportb(n))
pokeb(seg,ofs, peek(seg,ofs)+expr)

VAR parameters are translated into pointer variables;
references to formal parameters are implicitly dereferenced (i.e. * added);
references to actual parameters are implicitly referenced (i.e. & added).

Forward pointer type declarations are translated, but will not compile
in C. They must be manually recoded.

Variant record type declarations are translated into unions.

Absolute variables are translated into initialized pointer variables.



Support Pascal/MT+:
-------------------

Var declarations are translated from
ID external TYPE
into
extern TYPE ID.

The following expression operators are translated
from ! to | , | to |,
& to & , ~ to !,
? to ! , \ to !.

External function declarations are translated
from
external function NAME(V1: TYPE1; V2: TYPE2): TYPE3
external [n] function NAME(V1: TYPE1; V2: TYPE2): TYPE3
into
extern TYPE3 NAME()

External procedure declarations are translated
from
external procedure NAME(V1: TYPE1; V2: TYPE2)
external [n] procedure NAME(V1: TYPE1; V2: TYPE2)
into
extern void NAME()

Write and WriteLn are translated from:
write([ADDR(FUN)],VAR:n,VAR:n:m)
write([],VAR:n,VAR:n:m)
into
iprintf(FUN,"%nd%n.md",VAR,VAR)
printf("%nd%n.md",VAR,VAR)

Read and ReadLn are translated from:
read([ADDR(FUN)],VAR,VAR)
read([],VAR,VAR)
into
iscanf(FUN,"%d%nd%d",&VAR,&VAR,&VAR)
scanf("%d%nd%d",&VAR,&VAR,&VAR)

Long integer constants #nnn are translated into nnnL.



Some language features that are not yet translated:
---------------------------------------------------

File access procedures are only partially supported (assign, close,
etc.).

Variant record type decl's are translated into unions, but expressions
using the variant part are not translated.

C operator precedence differs from that of Pascal, and the differences
are not translated.

The WITH statement is not translated.

Local variable sharing among nested procedures is not translated.



Revision history
----------------

See HISTORY.DOC for the complete revision history.

I continue to update and improve TPTC. If you have a program that
TPTC will not translate, please send me a copy of it. This will help
me in future versions. I will not redistribute the file without your
permission.

Send sample sources to:
Samuel. H. Smith
(602) 279-2673 (data)
5119 N. 11 ave 332
Phoenix, Az 85013



  3 Responses to “Category : Pascal Source Code
Archive   : TPTC17.ZIP
Filename : TPTC.DOC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/