Principles of Programming Languages - GeeksforGeeks

22 Jan, 2014
Program main;
  Var ...
  
    Procedure A1;
     Var ...
     Call A2;
    End A1
    
    Procedure A2;
      Var ...
  
      Procedure A21;
        Var ...
        Call A1;
        End A21
        
    Call A21;
  End A21
  
    Call A1;
  End main.

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
1) Static allocation of all data areas by a compiler
   makes it impossible to implement recursion.
2) Automatic garbage collection is essential 
   to implement recursion.
3) Dynamic allocation of activation records is 
   essential to implement recursion.
4) Both heap and stack are essential to implement
   recursion.
subroutine swap(ix,iy)
     it = ix
L1 : ix = iy
L2 : iy = it
end
  ia = 3
  ib = 8
  call swap (ia, 1b+5)
  print *, ia, ib
end 
to bound cells to its subroutines, if they are already presentto unnamed temporary cells later to be bound, if they are not there
to bound cells to its subroutines, if they are already present
to unnamed temporary cells later to be bound, if they are not there
(S1) Because the second argument is an expression, which could be evaluated 
easily by compiler SDT rules to a value 13, compiler itself will generate code 
to define and declare an unnamed temporary cell with value 13 and pass it to swap 
subroutine. [CORRECT]

(S2) 'ix' and 'iy' are variables bound to valid mutable cells, thus there is no 
reason to get a run time error on line L1. [INCORRECT]

(S3) Incorrect due to same reason as of S2 [INCORRECT]

(S4) Due to the pass-by-reference nature of the language, the cell bound to 
variable 'ia' will get value 13 and the temporary unnamed cell which was allocated 
and passed to the swap subroutine will get value 3. Seemingly, cell bound to variable
 'ib' is unchanged, thus printing 13 and 8 at the end of this routine. [CORRECT]

(S5) Incorrect due to same reason as of S4 [INCORRECT]

Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, ...
Must Do Coding Questions for Product Based Companies
Split given String into substrings of size K by filling elements
SDE SHEET - A Complete Guide for SDE Preparation
DSA Sheet by Love Babbar
Java Threads
Top 20 Puzzles Commonly Asked During SDE Interviews
Software Testing Metrics, its Types and Example
Software Testing - Boundary Value Analysis
TCS NQT Coding Sheet