home *** CD-ROM | disk | FTP | other *** search
-
-
- 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 about much of the work required in
- a full translation.
-
- Usage: TPTC d:path\filename[.ext] outfile
-
- d: drive and path are optional
- ext defaults to .PAS
-
- Example:
- TPTC program.pas program.c
-
-
-
- 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.
-
- The following simple types are translated
- from BOOLEAN to char,
- INTEGER to int,
- REAL to double.
-
- 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].
-
- File types are translated from
- ID = text[N]
- ID = text
- 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;
- }.
-
- 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 ==,
- := to = .
-
- 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 a
- separate procedure declaration and parameter variable
- declarations, as required by C, e.g.
- from
- function NAME(V1: TYPE1; V2: TYPE2): TYPE3
- into
- TYPE3 NAME(V1,V2)
- 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 := VAR1 + "string"
- into
- strcpy(VAR, "string")
- strcpy(VAR, concat(VAR1, "string")).
-
- 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.
-
-
- The following translations were added to support Pascal/MT+:
- (version TPTC 1.4)
-
- 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.
-
- 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)
-
-
-
- Some language features that are not translated:
- -----------------------------------------------
-
- Local variable sharing among nested procedures is not translated.
-
- ***********
- VAR parameters must be manually recoded.
-
- File access procedures are only partially supported (assign, close,
- etc.).
-
- Ranges in the form VAL..VAL are not translated in case statements.
-
- Forward pointer type declarations are translated, but will not compile
- in C. They must be manually recoded.
-
- Variant record types should be translated into unions, but aren't.
-
- Bitwise AND and OR operators are always translated into the logical
- operators && and ||.
-
- C operator precedence differs from that of Pascal, and the differences
- are not translated.
-
- The WITH statement is not translated.
-
- ************
- The MEM[] and PORT[] arrays are not translated. These should be
- turned into function calls.
-
- Absolute variables are not (and probably cannot be) translated.
-
-
- Revision history
- ----------------
-
- 09/09/85 v0.0
- Initial coding by Samuel H. Smith. Never released.
-
- 12/19/86 v1.0
- First distributed as TPC10 under shareware concept.
-
- 04/15/87 v1.1
- Corrected handling of unary minus. Improved error messages; added
- error messages to object file. Added handler for integer subrange
- types. Added handling for goto statement and numeric labels. The
- macro header, tpcmac.h, now contains more declarations. Distributed
- as TPC11.
-
- 04/22/87 v1.2
- Corrected an error that led to a crash on lines with more than 40
- leading spaces. Distributed as TPC12.
-
- 05/20/87 v1.3
- Added support for pascal/MT+: external procedures and variables,
- special write/read indirect syntax, & and ! operators, default
- string size for string declarations. Distributed as TPC13.
-
- 05/26/87 v1.4
- Additional support for pascal/MT+. The translator "shifts" into a
- MT+ specific mode when it recognizes the 'MODULE' statement. The
- '|' operator is recognized for bitwise OR. The '\', '?' and '~'
- operators are all translated into a unary not (is this right,
- Noam?). Read(ln) and Write(ln) now support the special case of "[]"
- for the I/O routine. Long integer literals are translated from
- '#nnn' to 'nnnL'. Distributed as TPC14.
-
- additions - pretpc15
- translation if mem, memw, port and portw into turbo-c
- fixed bug in 'else' part of tpas case statement
- added some tpcmac.h declarations
-
- changes
- -- turbo-c procedure declaration syntax
- -- arrays subscripted by enumeration types
- -- fails to handle null else clause in case statement
- -- include intermediate cases in swith() .. case x..y
- -- pointer/var parameter translation *id.mem should be id->mem
- -- pointer/var parameter translation *id[n] should be id[n]
- -- concat(...)+char and string+char not detected as string/character
- concat operation.
- -- detect concat(concat... and replace with a sprintf variant
-
- -- changed sprintf calls to sbld calls to preserve sources during build
- -- pos(c,str) and pos(str,str) are now separately translated
-
- -- added 'base' to symbol table; use to add base-subscript offset
- in all subscript references.
- -- moved typename translations to tpcmac.h header
- -- fixed bug in non-translation of tshell directives
- -- forward pointer declarations
- -- translate inline into asm statements
- -- complete forward translation
-
- ---------------
- 13-oct-87
- -- improved string and array parameter translations
- -- string returns are now translated into char *
-
- 15-oct-87
- -- corrected error in typed constant translation where nested
- records are initialized.
- -- variant record declarations are translated into unions
- but no variant expression translations are done.
- -- changed nested procedure error messages to include procedure name.
-
-
- 02/13/88 v1.6
- Converted to TPAS 4.0 format; released under the SourceWare concept
- (see LICENSE.DOC). Documentation is still not ready...
-
-
-
-