📜  门|门CS 2008 |第 54 题

📅  最后修改于: 2021-09-26 03:33:22             🧑  作者: Mango

以下哪些是正确的?

I. A programming language which does not permit global variables of any
   kind and has no nesting of procedures/functions, but permits recursion 
   can be implemented with static storage allocation
II. Multi-level access link (or display) arrangement is needed to arrange 
    activation records only if the programming language being implemented 
    has nesting of procedures/functions
III. Recursion in programming languages cannot be implemented with dynamic 
     storage allocation
IV. Nesting of procedures/functions and recursion require a dynamic heap 
    allocation scheme and cannot be implemented with a stack-based allocation
    scheme for activation records
V. Programming languages which permit a function to return a function as its 
   result cannot be implemented with a stack-based storage allocation scheme 
   for activation records

(A)仅限 II 和 V
(B)仅 I、III 和 IV
(C)仅 I、II 和 V
(D)仅限 II、III 和 V答案:(一)
说明: I. 静态存储分配不能实现递归。静态分配意味着,编译器必须决定函数调用的大小。在递归的情况下,编译器不可能决定递归深度取决于递归参数,该参数也可能是用户的输入。

二、是正确的。支持嵌套子例程的编程语言在调用帧中也有一个字段,该字段指向最紧密封装被调用者的过程的最新激活的堆栈帧,即被调用者的直接范围。这称为访问链接静态链接(因为它在动态和递归调用期间跟踪静态嵌套)并提供例程(以及它可能调用的任何其他例程)在每次嵌套时访问其封装例程的本地数据等级。一些架构、编译器或优化案例为每个封闭级别(不仅仅是直接封闭的)存储一个链接,因此访问浅层数据的深度嵌套例程不必遍历多个链接;这种策略通常被称为“展示”[来源:https://en.wikipedia.org/wiki/Call_stack]

三、递归可以与任何类型的动态存储分配方案来实现。

四、嵌套功能总是在使用堆栈而不是堆的语言中实现。 (详见上文第二点)

V. 是正确的。在基于堆栈的分配方案中,一旦函数返回,它就会从函数调用堆栈中删除。因此,从函数返回函数看起来是不可能的。
这个问题的测验