Unit3 PPL
Unit3 PPL
1.What is subprogram?
Subprograms are the fundamental building blocks of programs and are
therefore among the most important concepts in programming language design
2. Define Fundamentals of Subprograms?
Each subprogram has a single entry point
The calling program unit is suspended during the execution of the called
subprogram
3.Define prototype?
.Prototype of a subprogram is its parameter. profile plus, if it is a function,
its return type.
.Function declarations are common in C and C++ programs, where they are
called prototypes such declarations are often placed in header files
4.What is Parameter-Passing Methods?
Parameter-passing methods are the ways in which parameters are transmitted
to and/or from called subprograms.
5.What are Semantics Models of Parameter Passing ?
Formal parameters are characterized by one of three distinct semantics
models:
In mode:
They can receive data from the corresponding actual parameter
Out mode:
They can transmit data to the actual parameter
Inout mode:
They can do both.
6. List the Implementation Models of Parameter Passing ?
1.Pass-by-Value
2.Pass-by-Result
3.Pass-by-name
4.Pass-by-Reference
5.Pass-by-Value-Result
7.What are the types of Returned Values ?
Most imperative programming languages restrict the types that can be
returned by their functions.
C allows any type to be returned by its functions except arrays and
functions. Both of these can be handled by pointer type return values.
8.What are the design Issues for Functions?
Are side effects allowed?
What types of values can be returned?
How many values can be returned?
9.Define overloaded subprogram?
An overloaded subprogram is one that has the same name as another
subprogram in the same referencing environment
10.Define generic subprogram?
A generic subprogram is one whose computation can be done on data of
different types in different calls.
11.What is polymorphic subprogarm?
A polymorphic subprogram takes parameters of different types on different
activations.
12.What is nested subprogram?
Some of the non– C- based static- scoped programming languages use stack-
dynamic local variables and allow subprograms to be nested. Among these are
Fortran 95+ Ada, Python, JavaScript, Ruby, and Lua, as well as the functional
languages.
13.Define static chain and static depth?
Static chain:
A static chain is a chain of static links that connect certain activation
record instances in the stack.
Static depth:
static_depth be an integer associated with a static scope that indicates
how deeply it is nested in the outermost scope.
14.What is the implementation of dynamic scoping?
There are at least two distinct ways in which.local variables and nonlocal
references to them can be implemented in a dynamic-scoped language: deep
access and shallow access.
15.Define deep access?
If local variables are stack dynamic and are part of the activation records in a
dynamic-scoped language, references to nonlocal variables can be resolved by
searching through the activation record instances of the other subprograms
16.Define shallow access?
Shallow access is an alternative implementation method, not an alternative
semantics.
As stated previously, the semantics of deep access and shallow access are
identical. In the shallow-access method, variables declared in subprograms are
not stored in the activation records of those subprograms.
17.What are the general characteristics of subprogram?
Each subprogram has a single entry point.
• The calling program unit is suspended during the execution of the called
subprogram, which implies that there is only one subprogram in execution at
any given time.
• Control always returns to the caller when the subprogram execution
terminates
18. Define subprogram linkage?
The subprogram call and return operations are together called subprogram
linkage.
The implementation of subprograms must be based on the semantics of the
subprogram linkage of the language being implemented.
19.What are the actions require for the simple subprogram in semantic calls?
1. Save the execution status of the current program unit.
2. Compute and pass the parameters.
3. Pass the return address to the called.
4. Transfer control to the called.
20.What are the actions require for the simple subprogram in semantic return ?
1.If there are pass-by-value-result or out-mode parameters,the current values
of those parameters are moved to or made available to the corresponding actual
parameters.
2. If the subprogram is a function, the functional value is moved to a place
accessible to the caller.
3. The execution status of the caller is restored.
4. Control is transferred back to the caller.
21.List out the storage required for call and return functions?
.Status information about the caller
• Parameters
• Return address
• Return value for functions
• Temporaries used by the code of the subprograms
22. What is the difference between an activation record and an activation record
instance?
Activation record :
The format, or layout, of the noncode part of a subprogram is called an
activation record, because the data it describes are relevant only during the
activation or execution of the subprogram. The form of an activation record is
static.
Activation record instance:
An activation record instance is a concrete example of an activation record,
a collection of data in the form of an activation record.
23.What is dynamic chain and local-offset?
Dynamic chain:
The collection of dynamic links present in the stack at a given time is called
the dynamic chain, or call chain.
Local-offset:
References to local variables can be represented in the code as offsets from
the beginning of the activation record of the local scope, whose address is stored
in the EP Such an offset is called a local_offset.
24.Define static link?
The static link, which is sometimes called a static scope pointer, points to
the bottom of the activation record instance of an activation of the static parent.
25.What is closure?
A closure is a simple matter; a closure is a subprogram and the referencing
environment where it was defined.