Re: c to Pascal translators?

anton@mips.complang.tuwien.ac.at (Anton Ertl)
15 Mar 1998 00:14:27 -0500

          From comp.compilers

Related articles
[6 earlier articles]
Re: c to Pascal translators? bweinra@uswest.com (Bret D Weinraub) (1998-03-05)
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: anton@mips.complang.tuwien.ac.at (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
results:


program x


procedure a(p: procedure(), i:integer)
    procedure b()
        begin
            writeln(i);
        end;
    begin
        if i=1 then
            a(b,2)
        else
            p();
    end;
procedure c()
    begin
    end;


begin (* main *)
    a(c,1);
end.


(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
"2".


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
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html
[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.