Consider the following program fragment in Pascal: Program Main; var X:…

PYQ GATE 1997Modified — slightly modified from the official paper; see the solution

Consider the following program fragment in Pascal:

Program Main;
    var X: integer;

    procedure A;
        var Y: integer;

        procedure B;
            var Z: integer;

            procedure C;
                var Z: integer;
            begin (* procedure C *)
                ...
            end; (* procedure C *)

        begin (* procedure B *)
            ...
            C; (* call to C *)
            A; (* call to A *)
            ...
        end; (* procedure B *)

    begin (* procedure A *)
        ...
        B; (* call to B *)
        ...
    end; (* procedure A *)

begin (* Main *)
    ...
    A; (* call to A *)
    ...
end. (* Main *)

Assume that there are no calls to any procedures other than the ones indicated above. At some point during execution, five activation records exist on the run-time stack. Describe the stack at this point, indicating its top, the static and dynamic links, and the local variables allocated in each record.

Sign up free to check your answer

Sign up free

Explore the full course: Compiler Design

Loading lesson…