SlideShare uma empresa Scribd logo
1 de 26
By-
Garima Jain
   Scope - Static and Dynamic
   Block Structures
   Local Data and Shared Data
   Parameter and Parameter Transmission
   Local and Common Environments
   Tasks and Shared Data
The dynamic scope of an association for an identifier :

 the set of subprogram activations in which the association
is visible during execution.
 tied to the dynamic chain of subprogram activations.


The static scope of a declaration :

 the part of the program text where the declared identifier
is used.
Dynamic scope rules :
relate references with associations for names during
program execution

Static scope rules :
relate references with declarations of names in the
program text.
Block-structured languages :

      • Each program or subprogram is organized as a set
      of nested blocks.

      • Each block introduces a new local referencing
      environment.
Subprogram A

Declaration of X
Declaration of Y

    Subprogram B       Static scope
    Declaration of Y   rules for
    Declaration of Z   block-
    Use of Y
                       structured
                       programs
    Use of X

    Use of Z           Hidden to A
Local environment of a subprogram:
various identifiers declared in the subprogram :
      variables, parameters, subprogram names.

Static scope rules: implemented by means of a table of the
local declarations

Dynamic scope rules:
       Retention - Associations and the bound values are
retained after execution
       Deletion - Associations are deleted
By means of a local environment table to associate
names, types and values.

Retention: the table is kept as part of the code segment

Deletion: the table is kept as part of the activation
record, destroyed after each execution.
Mechanisms to exchange data

Arguments - data objects sent to a subprogram to be
processed. Obtained through
      • parameters
      • non-local references

Results - data object or values delivered by the
subprogram. Returned through
      • parameters,
      • assignments to non-local variables, or
      • explicit function values
Parameter: A variable in a procedure that represents some other data
from the procedure that invoked the given procedure.

Parameter transmission: How that information is passed to the
procedure.
The parameter is also called the formal argument. The data from the
invoking procedure is called the actual argument or sometimes just
the argument.

Usual syntax:
Actual arguments: call P(A, B+2, 27+3)
Parameters: Procedure P(X, Y, Z)
What is connection between the parameters and the arguments?
Call by name
Call by reference
Call by value
Call by result (or value-result)
A formal parameter is a particular kind of local data object
within a subprogram.

It has a name, the declaration specifies its attributes.
An actual parameter is a data object that is shared with
the caller subprogram.

      a local data object belonging to the caller,
      a formal parameter of the caller,
      a non-local data object visible to the caller,
      a result returned by a function invoked by the caller
and immediately transmitted to the called subprogram.
Positional correspondence – pairing actual and formal
parameters based on their respective positions in the
actual- and formal- parameter lists

Correspondence by explicit name – The name is
paired explicitly by the caller.
Call by name - the actual parameter is substituted in the
subprogram

Call by reference – a pointer to the location of the data
object is made available to the subprogram.
The data object does not change position in memory.

Call by value – the value of the actual parameter is copied
in the location of the formal parameter.
Call by value-result – same as call by values, however at
the end of execution the result is copied into the actual
parameter.


Call by result – A parameter transmitted by result is used
only to transmit a result back from a subprogram. The
initial value of the actual-parameter data object makes no
difference and cannot be used by the subprogram.
Call by constant value – no change in the value
of the formal parameter is allowed during program
execution.

The formal parameter acts as a local constant
during the execution of the subprogram.
Pass by name in Algol Pass by reference in FORTRAN

procedure S (el, k); SUNROUTINE S(EL, K)
  integer el, k;              K = 2
  begin                       EL = 0
    k:=2;                 RETURN
    el := 0               END
  end;

A[1] := A[2] := 1;        A(1) = A(2) = 1
i := 1;                   I = 1
S(A[i],i);                CALL S (A(I), I)
After calling S(A[i], i), the effect is as if the
procedure were

      i := 2;
      A[i] := 0;

As a result A[2] becomes 0.

On exit we have
i = 2, A[1] = 1, A[2] = 0.
Since at the time of call i is 1, the formal
parameter el is linked to the address of A(1).

Thus it is A(1) that becomes 0.

On exit we have: i = 2, A(1) = 0, A(2) = 1
Types of parameters:
 input information
 output information (the result)
 both input and output

The three types can be accomplished by copying or using
pass-by-reference

Return results:
             Using parameters
             Using functions with a return value
Implementing formal parameters:
       Storage - in the activation record
       Type:
             Local data object of type T in case of pass by
value, pass by value-result, pass by result
             Local data object of type pointer to T in case of
pass by reference

Call by name implementation: the formal parameters are
subprograms that evaluate the actual parameters.
Associated with the point of call of the
subprogram

  each actual parameter is evaluated in the
  referencing environment of the calling
  program, and a list of pointers is set up.
Associated with the entry and exit in the subprogram

on entry:
      copying the entire contents of the actual parameter
      in the formal parameter, or copying the pointer to
      the actual parameter
on exit:
      copying result values into actual parameters
      or copying function values into registers
Specification: A common environment not local to any
single subprogram.
     It may contain:
            definitions of variables, constants, types.
     It cannot contain:
            subprograms, formal parameters.

Implementation: as a separate block of memory
storage.
1. Generate prologue and epilogue code to perform the
actions on entry and exit .
This code is stored in the segment code part of the
activation record of the subprogram


2. Perform the necessary static type checking
Unit 4

Mais conteúdo relacionado

Mais procurados (20)

Java Streams
Java StreamsJava Streams
Java Streams
 
Recursion - Algorithms and Data Structures
Recursion - Algorithms and Data StructuresRecursion - Algorithms and Data Structures
Recursion - Algorithms and Data Structures
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
virtual function
virtual functionvirtual function
virtual function
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
stack & queue
stack & queuestack & queue
stack & queue
 
LL(1) parsing
LL(1) parsingLL(1) parsing
LL(1) parsing
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
 

Semelhante a Unit 4 (20)

Ch07
Ch07Ch07
Ch07
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
 
10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprograms
 
Subprogramms
SubprogrammsSubprogramms
Subprogramms
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
 
C functions list
C functions listC functions list
C functions list
 
Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on line
 
chapter-7-runtime-environments.ppt
chapter-7-runtime-environments.pptchapter-7-runtime-environments.ppt
chapter-7-runtime-environments.ppt
 
Function in c
Function in cFunction in c
Function in c
 
Functions
FunctionsFunctions
Functions
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
Functions
FunctionsFunctions
Functions
 
Function in c
Function in cFunction in c
Function in c
 
FUNCTIONS1.pptx
FUNCTIONS1.pptxFUNCTIONS1.pptx
FUNCTIONS1.pptx
 
Functions in c language1
Functions in c language1Functions in c language1
Functions in c language1
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdf
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Functions in Python.pdfnsjiwshkwijjahuwjwjw
Functions in Python.pdfnsjiwshkwijjahuwjwjwFunctions in Python.pdfnsjiwshkwijjahuwjwjw
Functions in Python.pdfnsjiwshkwijjahuwjwjw
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 

Último (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 

Unit 4

  • 2. Scope - Static and Dynamic  Block Structures  Local Data and Shared Data  Parameter and Parameter Transmission  Local and Common Environments  Tasks and Shared Data
  • 3. The dynamic scope of an association for an identifier :  the set of subprogram activations in which the association is visible during execution.  tied to the dynamic chain of subprogram activations. The static scope of a declaration :  the part of the program text where the declared identifier is used.
  • 4. Dynamic scope rules : relate references with associations for names during program execution Static scope rules : relate references with declarations of names in the program text.
  • 5. Block-structured languages : • Each program or subprogram is organized as a set of nested blocks. • Each block introduces a new local referencing environment.
  • 6. Subprogram A Declaration of X Declaration of Y Subprogram B Static scope Declaration of Y rules for Declaration of Z block- Use of Y structured programs Use of X Use of Z Hidden to A
  • 7. Local environment of a subprogram: various identifiers declared in the subprogram : variables, parameters, subprogram names. Static scope rules: implemented by means of a table of the local declarations Dynamic scope rules: Retention - Associations and the bound values are retained after execution Deletion - Associations are deleted
  • 8. By means of a local environment table to associate names, types and values. Retention: the table is kept as part of the code segment Deletion: the table is kept as part of the activation record, destroyed after each execution.
  • 9. Mechanisms to exchange data Arguments - data objects sent to a subprogram to be processed. Obtained through • parameters • non-local references Results - data object or values delivered by the subprogram. Returned through • parameters, • assignments to non-local variables, or • explicit function values
  • 10. Parameter: A variable in a procedure that represents some other data from the procedure that invoked the given procedure. Parameter transmission: How that information is passed to the procedure. The parameter is also called the formal argument. The data from the invoking procedure is called the actual argument or sometimes just the argument. Usual syntax: Actual arguments: call P(A, B+2, 27+3) Parameters: Procedure P(X, Y, Z) What is connection between the parameters and the arguments? Call by name Call by reference Call by value Call by result (or value-result)
  • 11. A formal parameter is a particular kind of local data object within a subprogram. It has a name, the declaration specifies its attributes.
  • 12. An actual parameter is a data object that is shared with the caller subprogram. a local data object belonging to the caller, a formal parameter of the caller, a non-local data object visible to the caller, a result returned by a function invoked by the caller and immediately transmitted to the called subprogram.
  • 13. Positional correspondence – pairing actual and formal parameters based on their respective positions in the actual- and formal- parameter lists Correspondence by explicit name – The name is paired explicitly by the caller.
  • 14. Call by name - the actual parameter is substituted in the subprogram Call by reference – a pointer to the location of the data object is made available to the subprogram. The data object does not change position in memory. Call by value – the value of the actual parameter is copied in the location of the formal parameter.
  • 15. Call by value-result – same as call by values, however at the end of execution the result is copied into the actual parameter. Call by result – A parameter transmitted by result is used only to transmit a result back from a subprogram. The initial value of the actual-parameter data object makes no difference and cannot be used by the subprogram.
  • 16. Call by constant value – no change in the value of the formal parameter is allowed during program execution. The formal parameter acts as a local constant during the execution of the subprogram.
  • 17. Pass by name in Algol Pass by reference in FORTRAN procedure S (el, k); SUNROUTINE S(EL, K) integer el, k; K = 2 begin EL = 0 k:=2; RETURN el := 0 END end; A[1] := A[2] := 1; A(1) = A(2) = 1 i := 1; I = 1 S(A[i],i); CALL S (A(I), I)
  • 18. After calling S(A[i], i), the effect is as if the procedure were i := 2; A[i] := 0; As a result A[2] becomes 0. On exit we have i = 2, A[1] = 1, A[2] = 0.
  • 19. Since at the time of call i is 1, the formal parameter el is linked to the address of A(1). Thus it is A(1) that becomes 0. On exit we have: i = 2, A(1) = 0, A(2) = 1
  • 20. Types of parameters:  input information  output information (the result)  both input and output The three types can be accomplished by copying or using pass-by-reference Return results: Using parameters Using functions with a return value
  • 21. Implementing formal parameters: Storage - in the activation record Type: Local data object of type T in case of pass by value, pass by value-result, pass by result Local data object of type pointer to T in case of pass by reference Call by name implementation: the formal parameters are subprograms that evaluate the actual parameters.
  • 22. Associated with the point of call of the subprogram each actual parameter is evaluated in the referencing environment of the calling program, and a list of pointers is set up.
  • 23. Associated with the entry and exit in the subprogram on entry: copying the entire contents of the actual parameter in the formal parameter, or copying the pointer to the actual parameter on exit: copying result values into actual parameters or copying function values into registers
  • 24. Specification: A common environment not local to any single subprogram. It may contain: definitions of variables, constants, types. It cannot contain: subprograms, formal parameters. Implementation: as a separate block of memory storage.
  • 25. 1. Generate prologue and epilogue code to perform the actions on entry and exit . This code is stored in the segment code part of the activation record of the subprogram 2. Perform the necessary static type checking