- Pascal to Component Pascal translator & Name Translation & Character Translation to Unicode

From: collection <"collection">
Date: Sat, 22 Oct 2005 00:39:36 +0200

Dear Chris,

it is a typical Benchmark problem that some relevant topics are not compared. The aim of Tp2cp is not to get a immediately running program after translation. It has the 80 to 20 approach: Get 80% translated with 20% effort.


The most important topic is comments inside programs. Tp2cp passes all comments from the source to the translated result.
What does P20 do with comments?

The second important topic is the name translations and adding subsystem names. Suppose you have to translate a bigger project with a lot of Units (MODULEs) and you would like to have the result into the same subsystem. We implement name translations and adding the subsystem names.

E.g. the symbol table have the following entries:

        .DynLib C2pasStrings
        DynLib.DynString

        .Keytab C2pasKeytab
        Keytab.Keyword GetKeyword

then we translate with Tp2cp the source

        PROCEDURE GetIdentifier* (index: INTEGER): DynString;
        BEGIN
                GetIdentifier := Keyword(symtable[index].identifier)
        END GetIdentifier;

to

        PROCEDURE GetIdentifier* (index: INTEGER): C2cpStrings.DynString;
        BEGIN
                RETURN C2cpKeytab.GetKeyword(symtable[index].identifier)
        END GetIdentifier;

Have P20 a name translations?

That was very helpfully at my project to translate C2cp from Turbo Pascal to Component Pascal. After I solved the topic of the different string handling between TP (starts with index 1 index 0 = length of string) und CP (starts with index 0 end ends with 0X) the program was running.


We separate the translation from (Turbo) Pascal to Component Pascal into 4 different modules:

        1. Translation from TP to CP with Tp2cp and using name translation via symbol table.
        2. Beautify the result with CpcBeautifier and if necessary type translations (see options)
        3. Translation of enumerated types with CpcPreprocessor
        4. Translate the characters to Unicode TboxAutoCharEdit (not published yet)

An other topic is the character translations. Old Turbo Pascal uses the IBM-PC extended ASCII character set. I can translate this character set with module 4 to Unicode but the result is not working. See my last email via Black Box Mailing list.

Have P20 a character translations?


Regards

Helmut Zinn



-----Ursprüngliche Nachricht-----
Von: blackbox{([at]})nowhere.xy
Software
Gesendet: Mittwoch, 19. Oktober 2005 05:48
An: BlackBox Mailing List
Betreff: [BlackBox] - Pascal to Component Pascal translator

> Sounds good. How does it differ from Tp2Cp?

Gérard Meunier (the author of Tp2Cp) asked exactly the same question on
the GPCP mailing list. My response was:

The end results are very similar for the Pascal programs that I have
tested with both translators. Yours (Tp2Cp) does more to handle
Turbo-related code. The following example (unashamedly contrived to show
my (P2O) best points!) illustrates the major differences:

Original Pascal Source:
=======================

program test;

type
  enum = (first, middle, last);
  subrange = 0..10;
  rec = record
  i: integer;
  j: integer
end;

var
  j, k: integer;
  r: rec;

begin
  with r do begin
    i := j;
    j := k
  end;

if j = 0 then
  j := 1
else if j = 1 then
  j := 0;
end.


Tp2Cp Translation
=================

MODULE test;

TYPE
  enum = (first, middle, last);
  subrange = 0..10;
  rec = RECORD
    i: INTEGER;
    j: INTEGER
  END;
 
VAR
  j, k: INTEGER;
  r: rec;

PROCEDURE Main*;
BEGIN
  WITH r DO
    i := j;
    j := k
  END;
  
  IF j = 0 THEN
    j := 1
  ELSE IF j = 1 THEN
    j := 0 END END;
END Main;
END test.

P2O Translation
===============

MODULE test;

TYPE
  enum = INTEGER;
CONST first = 0; middle = 1; last = 2;
  subrange = INTEGER;
  rec = RECORD
    i: INTEGER;
    j: INTEGER
  END;
 
VAR
  j, k: INTEGER;
  r: rec;

BEGIN
  (* WITH r DO *)
    
    r.i := r.j;
    
    r.j := k
  (* END WITH *);
  
  IF j = 0 THEN
    j := 1
  ELSIF j = 1 THEN
    j := 0
  END;
END test.

=============

Note1: WITH handling is currently only working for the simplest cases.

Note2: The CONST statements generated from enumerated types need to be
relocated above the TYPE section before attempting to compile the
translated code.

Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy





Received on Sat Oct 22 2005 - 00:39:36 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:28:07 UTC