Re: c to Pascal translators?

torbenm@diku.dk (Torben AEgidius Mogensen)
18 Mar 1998 22:48:55 -0500

          From comp.compilers

Related articles
[7 earlier articles]
Re: c to Pascal translators? bear@sonic.net (Ray Dillinger) (1998-03-06)
Re: c to Pascal translators? fpeelo@portablesolutions.com (Frank Peelo) (1998-03-07)
Re: c to Pascal translators? RogerHA@aol.com (RogerHA) (1998-03-08)
Re: c to Pascal translators? joachim.durchholz@munich.netsurf.de (Joachim Durchholz) (1998-03-12)
Re: c to Pascal translators? albaugh@agames.com (1998-03-12)
Re: c to Pascal translators? anton@mips.complang.tuwien.ac.at (1998-03-15)
Re: c to Pascal translators? torbenm@diku.dk (1998-03-18)
| List of all articles for this month |

From: torbenm@diku.dk (Torben AEgidius Mogensen)
Newsgroups: comp.compilers
Date: 18 Mar 1998 22:48:55 -0500
Organization: Department of Computer Science, U of Copenhagen
References: 98-03-068 98-03-089 98-03-123
Keywords: C, Pascal, translator, Lisp

anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:


>[Shallow binding] worked for (pre-common) LISP, because LISP used dynamic
>scoping. It does not work for Pascal, because it is a statically
>scoped language. Here's an example where it will produce the wrong
>results:


Example using procedures-as-parameters deleted.


You don't need procedure parameters to get incorrect behaviour of
shallow binding in Pascal. It is enough to have call-by-reference
(var) parameters. An example is


procedure p(var x : integer)
var y : integer;
begin
    if x>0 then begin
        y := x-1;
        writeln(x);
        x := -7;
        p(y);
        writeln(y)
    end
end;


var x0 : integer;


begin
    x0 := 2;
    p(x0)
end;


In "real" Pascal, you would print the sequence 2, 1, 0, -7. With
shallow binding, the second call will make x point to the newest
instance of y instead of the instance from the calling procedure and
when returning from p the old value of y will be restored regardless
of modifications to it through x. Hence, the program will print the
sequence 2, 0, -7, 1.


>BTW, not all statically scoped languages have this problem. E.g., in
>Modula-2 shallow binding would work, because it only allows passing
>level-0 procedures.


By the above argument, I would say that it is incorrect to implement
Modula-2 (which has var-parameters) by shallow binding.


But Anton Ertl is correct in saying that not all statically scoped
languages have the problem. If you have a language that does not allow
procedures as parameters and does not have call-by-reference
parameters (or other ways of obtaining the address of a variable),
then shallow and deep binding should be equivalent.


Torben Mogensen (torbenm@diku.dk)
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.