Re: c to Pascal translators? (Anton Ertl)
15 Mar 1998 00:14:27 -0500

          From comp.compilers

Related articles
[6 earlier articles]
Re: c to Pascal translators? (Bret D Weinraub) (1998-03-05)
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: (Anton Ertl)
Newsgroups: comp.compilers
Date: 15 Mar 1998 00:14:27 -0500
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
References: 98-03-068 98-03-089
Keywords: C, Pascal, translator, Lisp, comment

Our dear moderator writes:

> [Shallow binding is a traditional Lisp technique where variables are
> stored in fixed places, and function prolog and epilog saves and
> restores their values in anonymous stack temporaries to allow
> recursion. You can think of it as the names hold still and the values
> move. The more common compiled code approach where you rename locals
> to refer to locations in the current stack frame is known as deep
> binding. Both work, and have different tradeoffs. There the values
> hold still and the names move. So, yes, you really can make the local
> variables file scope statics if you have suitable code in your procedures.
> -John]

This technique 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

program x

procedure a(p: procedure(), i:integer)
    procedure b()
        if i=1 then
procedure c()

begin (* main *)

(Sorry if I made some syntax errors; it's been a long time since I
last programmed in Pascal).

This program should print "1", but with shallow binding it would print

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.

- anton
M. Anton Ertl Some things have to be seen to be believed Most things have to be believed to be seen
[Hmmn, there must be some way to fudge that. Will ponder. -John]

Post a followup to this message

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