Re: c to Pascal translators? (Torben AEgidius Mogensen)
18 Mar 1998 22:48:55 -0500

          From comp.compilers

Related articles
[7 earlier articles]
Re: c to Pascal translators? (Ray Dillinger) (1998-03-06)
Re: c to Pascal translators? (Frank Peelo) (1998-03-07)
Re: c to Pascal translators? (RogerHA) (1998-03-08)
Re: c to Pascal translators? (Joachim Durchholz) (1998-03-12)
Re: c to Pascal translators? (1998-03-12)
Re: c to Pascal translators? (1998-03-15)
Re: c to Pascal translators? (1998-03-18)
| List of all articles for this month |

From: (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 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

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;
    if x>0 then begin
        y := x-1;
        x := -7;

var x0 : integer;

    x0 := 2;

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 (

Post a followup to this message

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