help on activation tree

"steve_bagnall" <steve.bagnall@gmail.com>
11 Sep 2006 15:53:36 -0400

          From comp.compilers

Related articles
help on activation tree steve.bagnall@gmail.com (steve_bagnall) (2006-09-11)
| List of all articles for this month |
From: "steve_bagnall" <steve.bagnall@gmail.com>
Newsgroups: comp.compilers
Date: 11 Sep 2006 15:53:36 -0400
Organization: http://groups.google.com
Keywords: code, question
Posted-Date: 11 Sep 2006 15:53:36 EDT

Hi,


The following is a question I'm struggling with, it's an abbreviation
of Q2.5b from the Dragon book, I was wondering if anyone can help me
get my answer right:


In a language that has dynamic binding of names to memory addresses,
employing deep binding and a scoping rule that allows a reference to
point to the closest ancestor in the activation tree that holds a
declaration. Given the following functions; what is the tree of
activation records when A is evaluated. I have used F * G to denote
the composition of two functions F and G.


function F(X);
      function X, Y;
      Y := X * H;
      return Y;
end F;


function H();
      return SIN;
end H;


function G(Z)
      function Z, W;
      W := ARCTAN * Z;
      return W;
end G;


function MAIN();
      real A;
      function U, V;
      V := F(G);
      U := V();
      A := U(PI / 2);
      print A;
end MAIN;


At the moment my thinking is as follows:


----------------------------------------------------
| MAIN |
----------------------------------------------------
| A = 0.7854 [ ARCTAN(SIN(PI / 2)) ] |
| U = Y |
| V = Y |
----------------------------------------------------
                |
-------------------
| F |
-------------------
| X = G |
| Y = X * H |
-------------------
                    |
-----------------------
| Y [ ARCTAN * SIN ] |
-----------------------


But I'm not sure about this, because I'm not sure that the activation
record for the dynamic function that I've called Y should be called Y,
and also what data it should hold.


Also, the statement: U := V() seems to suggest that you should call the
function V() and assign the return value to U, but at that point V is
the composition of ARCTAN and SIN and I don't see how that can take no
parameters, so I've just assigned the function that V points to to U?


Plus in general, this doesn't look much like a tree, which the question
seemed to suggest I would create, making me think I've got it totally
wrong.


I'd appreciate any pointers at all on this one. By the way I'm not a
student or anything so this is not cheating.


Cheers,
Steve.


Post a followup to this message

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