home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TPTC17.ZIP / TPTC.DOC < prev    next >
Encoding:
Text File  |  1988-03-25  |  11.2 KB  |  385 lines

  1.  
  2.  
  3.                        TPTC16 - Translate Pascal to C
  4.                            Version 1.6, 13-Feb-88
  5.  
  6.                  (C) Copyright 1986, 1988 by Samuel H. Smith
  7.                             All rights reserved.
  8.  
  9.  
  10. This program will read a turbo pascal source file and convert it into
  11. the  corresponding C source code.   It does much of the work required in
  12. a full translation.
  13.  
  14. Usage:   TPTC input_file [output_file] [options]
  15.  
  16. Where:   input_file      specifies the main source file, .PAS default
  17.          output_file     specifies the output file, .C default
  18.          -B              deBug trace during scan
  19.          -BP             deBug trace during Parse
  20.          -D              Dump user symbols
  21.          -DP             Dump Predefined system symbols
  22.          -I              output Include files' contents
  23.          -L              map all identifiers to Lower case
  24.          -M              use Pascal/MT+ specific translations
  25.          -NC             No Comments passed to output file
  26.          -Q              Quiet mode; suppress warnings
  27.          -Sdir\          search dir\ for .UNS symbol files
  28.          -Tnn            Tab nn columns in declarations
  29.          -Wdrive:        use drive: for Work/scratch files (ramdrive)
  30.          -#              don't translate lines starting with "#"
  31.  
  32. Default command parameters are loaded from TPTC environment variable.
  33.  
  34. Example: tptc fmap
  35.          tptc fmap -L -d -wj:\tmp\
  36.          tptc -l -d -wj: -i -q -t15 fmap.pas fmap.out
  37.  
  38.          set tptc=-wj: -i -l -sc:\libs
  39.          tptc test       ;uses options specified earlier
  40.  
  41.  
  42. LICENSE
  43. =======
  44.  
  45.    SourceWare: What is it?
  46.    -----------------------
  47.    SourceWare is my name for a unique concept in user supported software. 
  48.    
  49.    Programs distributed under the SourceWare concept always offer complete 
  50.    source code. 
  51.  
  52.    This package can be freely distributed so long as it is not modified 
  53.    or sold for profit.  If you find that this program is valuable,  you 
  54.    can send me a donation for what you think it is worth.  I suggest
  55.    about $20.
  56.  
  57.    Send your contributions to:
  58.       Samuel. H. Smith
  59.       5119 N. 11 ave 332
  60.       Phoenix, Az 85013
  61.  
  62.  
  63.    Why SourceWare?
  64.    ---------------
  65.    Why do I include source code?  Why isn't the donation manditory?  The
  66.    value of good software should be self-evident.  The source code is
  67.    the key to complete understanding of a program.  You can read it to
  68.    find out how things are done.  You can also change it to suit your
  69.    needs, so long as you do not distribute the modified version without
  70.    my consent.
  71.  
  72.  
  73.    Copyright
  74.    ---------
  75.    If you modify this program, I would appreciate a copy of the new
  76.    source code.   I am holding the copyright on the source code, so
  77.    please don't delete my name from the program files or from the
  78.    documentation.
  79.  
  80.  
  81. SUPPORT
  82. =======
  83.  
  84.    I work very hard to produce a software package of the highest
  85.    quality and functionality.  I try to look into all reported bugs, and
  86.    will generally fix reported problems within a few days.
  87.  
  88.    Since this is user supported software under the SourceWare  concept,
  89.    I don't expect you to contribute if you don't like it or if it
  90.    doesn't meet your needs.
  91.  
  92.    If you have any questions, bugs, or suggestions, please contact  me
  93.    at:  The Tool Shop BBS (602) 279-2673
  94.  
  95.    The latest version is always available for downloading. 
  96.  
  97.    Enjoy!     Samuel H. Smith
  98.               Author and Sysop of The Tool Shop.
  99.  
  100.  
  101.  
  102.  
  103. The following language constructs are translated:
  104. ------------------------------------------------
  105.  
  106.    Comments are translated from either {...} or (*...*) into /*...*/.
  107.  
  108.    Begin and End are translated into { and }.
  109.  
  110.    Const declarations are translated from
  111.       ID = VALUE
  112.    into
  113.       static ID = VALUE.
  114.  
  115.    Simple Var declarations are translated from
  116.       ID TYPE
  117.    into
  118.       TYPE ID.
  119.  
  120.    Integer subrange types are translated into integers.
  121.  
  122.    Record types are translated from
  123.       ID = record MEMBER-LIST end
  124.    into
  125.       typedef struct { MEMBER-LIST } ID.
  126.  
  127.    Enumeration types are translated from
  128.       ID = (...)
  129.    into
  130.       typedef enum {...} ID.
  131.  
  132.    Array types are translated from
  133.       ID = array [RANGE] of TYPE
  134.    into
  135.       typedef TYPE ID[RANGE].
  136.  
  137.    Pointer types are translated from
  138.       ID = ^DEFINED-TYPE
  139.    into
  140.       DEFINED-TYPE *ID.
  141.  
  142.    String types are translated from
  143.       ID = string[N]
  144.    into
  145.       typedef char ID[N+1].
  146.  
  147.    File types are translated from
  148.       ID = text[N]
  149.       ID = file
  150.    into
  151.       FILE *ID
  152.       int ID.
  153.  
  154.    For statements are translated from
  155.       for VAR := FIRST to LAST do STATEMENT
  156.       for VAR := FIRST downto LAST do statement
  157.    into
  158.       for (VAR = FIRST; VAR <= LAST; VAR++) STATEMENT
  159.       for (VAR = FIRST; VAR >= LAST; VAR--) STATEMENT
  160.  
  161.    While statements are translated from
  162.       while COND do STATEMENT
  163.    into
  164.       while (COND) statement.
  165.  
  166.    Repeat statements are translated from
  167.       repeat STATEMENTS until COND
  168.    into
  169.       do { STATEMENTS } while(!COND).
  170.  
  171.    If statements are translated from
  172.       if COND then STATEMENT else STATEMENT
  173.    into
  174.       if (COND) STATEMENT; else STATEMENT.
  175.  
  176.    Case statements are translated from
  177.       case VALUE of
  178.          V:    STATEMENT;
  179.          V,U:  STATEMENT;
  180.          else  STATEMENT
  181.       end
  182.    into
  183.       switch (VALUE) {
  184.          case V:  STATEMENT; break;
  185.          case V:
  186.          case U:  STATEMENT; break;
  187.          default: STATEMENT;
  188.       }.
  189.       
  190.    Ranges in the form VAL..VAL automatically include cases for 
  191.    intermediate values.
  192.  
  193.    The IN operator is translated from
  194.       VAL in [A,B,C]
  195.     into
  196.       inset(VAL, setof(A,B,C,-1)).
  197.  
  198.    The ParamCount and ParamStr functions are translated from
  199.       paramcount
  200.       paramstr(n)
  201.    into
  202.       argc
  203.       argv[n].
  204.  
  205.    Dummy parameter lists are added to function and procedure calls,
  206.    where they are required in C but not in Pascal.
  207.  
  208.    The following expression operators are translated
  209.       from  DIV  to  / ,     MOD  to  % ,
  210.             AND  to  &&,     OR   to  ||,
  211.             XOR  to  ~ ,     <>   to  !=,
  212.             NOT  to  ! ,     SHR  to  >>,
  213.             SHL  to  <<,     =    to  ==,               {+others}
  214.             :=   to  = .
  215.    Bitwise AND and OR operators are translated into & and |.
  216.  
  217.    The '^' symbol is translated
  218.       from  VAR^          to  *VAR,
  219.             VAR^.MEMBER   to  VAR->MEMBER.
  220.  
  221.    Exit statements are translated
  222.       from  exit    to  return.
  223.  
  224.    The New operator is translated from
  225.       new(VAR)
  226.    into
  227.       VAR = malloc(sizeof(*VAR)).
  228.  
  229.  
  230.    Procedure/function formal parameter lists are translated into the
  231.       new form defined in ANSI C (and as used by Turbo C):
  232.    from
  233.       function NAME(V1: TYPE1; V2: TYPE2): TYPE3
  234.    into
  235.       TYPE3 NAME(TYPE1 V1,TYPE2 V2)
  236.  
  237.    Procedures are translated into functions with 'void' return types.
  238.  
  239.    The special character literal syntax, ^C or #nn, is translated into
  240.    '\ooo', where ooo is the octal notation for the ascii code.
  241.  
  242.    Hex constants $hhhh are translated into 0xhhhh.
  243.  
  244.    Write and WriteLn are translated from:
  245.       write(VAR,VAR:n,VAR:n:m)
  246.       writeln(FILE,VAR,VAR,VAR)
  247.    into
  248.       printf("%d%nd%n.md",VAR,VAR,VAR)
  249.       fprintf(FILE,"%d%d%d\n",VAR,VAR,VAR).
  250.  
  251.    Read and ReadLn are translated from:
  252.       read(VAR,VAR,VAR)
  253.       readln(FILE,VAR,VAR,VAR)
  254.    into
  255.       scanf("%d%nd%d",&VAR,&VAR,&VAR)
  256.       fscanf(FILE,"%d%d%d\n",&VAR,&VAR,&VAR).
  257.  
  258.    String assignments are translated from:
  259.       VAR := "string"
  260.       VAR := "string1(" + VAR1 + ")string2"
  261.    into
  262.       strcpy(VAR, "string")
  263.       sbld(VAR,"string1(%s)string2",VAR1).      {+other compound forms}
  264.  
  265.    String comparisons are translated from:
  266.       VAR == "string"
  267.       VAR < "string"
  268.       "string" >= VAR
  269.    into
  270.       (strcmp(VAR,"string") == 0)
  271.       (strcmp(VAR,"string") < 0)
  272.       (strcmp("string",VAR) >= 0).
  273.  
  274.    Function value assignments are translated from:
  275.       FUN_NAME := expr
  276.    into
  277.       return expr.
  278.  
  279.    Numeric statement labels are translated to label_nn.  
  280.    Label identifiers are not changed.  
  281.    Local GOTO statements are handled properly. 
  282.  
  283.    Nested procedures are "flattened" out, but local variable sharing and 
  284.    local scoping are not translated. 
  285.  
  286.    Direct I/O port and memory references are translated:
  287.       portw[expr] := expr + port[n]
  288.       mem[seg:ofs] := memw[seg:ofs] + expr
  289.    into
  290.       outport(expr, expr+inportb(n))
  291.       pokeb(seg,ofs, peek(seg,ofs)+expr)
  292.  
  293.    VAR parameters are translated into pointer variables; 
  294.    references to formal parameters are implicitly dereferenced (i.e. * added);
  295.    references to actual parameters are implicitly referenced (i.e. & added).
  296.  
  297.    Forward pointer type declarations are translated, but will not compile 
  298.    in C.  They must be manually recoded. 
  299.  
  300.    Variant record type declarations are translated into unions.
  301.  
  302.    Absolute variables are translated into initialized pointer variables.
  303.    
  304.  
  305.  
  306. Support Pascal/MT+:
  307. -------------------
  308.  
  309.    Var declarations are translated from
  310.       ID external TYPE
  311.    into
  312.       extern TYPE ID.
  313.  
  314.    The following expression operators are translated
  315.       from   !   to  | ,    |    to   |,
  316.              &   to  & ,    ~    to   !,
  317.              ?   to  ! ,    \    to   !.
  318.  
  319.    External function declarations are translated
  320.    from
  321.       external function NAME(V1: TYPE1; V2: TYPE2): TYPE3
  322.       external [n] function NAME(V1: TYPE1; V2: TYPE2): TYPE3
  323.    into
  324.       extern TYPE3 NAME()
  325.  
  326.    External procedure declarations are translated
  327.    from
  328.       external procedure NAME(V1: TYPE1; V2: TYPE2)
  329.       external [n] procedure NAME(V1: TYPE1; V2: TYPE2)
  330.    into
  331.       extern void NAME()
  332.  
  333.    Write and WriteLn are translated from:
  334.       write([ADDR(FUN)],VAR:n,VAR:n:m)
  335.       write([],VAR:n,VAR:n:m)
  336.    into
  337.       iprintf(FUN,"%nd%n.md",VAR,VAR)
  338.       printf("%nd%n.md",VAR,VAR)
  339.  
  340.    Read and ReadLn are translated from:
  341.       read([ADDR(FUN)],VAR,VAR)
  342.       read([],VAR,VAR)
  343.    into
  344.       iscanf(FUN,"%d%nd%d",&VAR,&VAR,&VAR)
  345.       scanf("%d%nd%d",&VAR,&VAR,&VAR)
  346.  
  347.    Long integer constants #nnn are translated into nnnL.
  348.  
  349.  
  350.  
  351. Some language features that are not yet translated:
  352. ---------------------------------------------------
  353.  
  354.    File access procedures are only partially supported (assign, close, 
  355.    etc.). 
  356.  
  357.    Variant record type decl's are translated into unions, but expressions
  358.    using the variant part are not translated.
  359.  
  360.    C operator precedence differs from that of Pascal, and the differences 
  361.    are not translated. 
  362.  
  363.    The WITH statement is not translated.
  364.  
  365.    Local variable sharing among nested procedures is not translated. 
  366.  
  367.  
  368.  
  369. Revision history
  370. ----------------
  371.  
  372.   See HISTORY.DOC for the complete revision history.
  373.   
  374.   I continue to update and improve TPTC.  If you have a program that
  375.   TPTC will not translate, please send me a copy of it.  This will help
  376.   me in future versions.  I will not redistribute the file without your
  377.   permission.
  378.  
  379.   Send sample sources to:
  380.       Samuel. H. Smith
  381.       (602) 279-2673 (data)
  382.       5119 N. 11 ave 332
  383.       Phoenix, Az 85013
  384.  
  385.