SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere Àhnliche Inhalte

Was ist angesagt?

Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design) Tasif Tanzim
 
2.2. language evaluation criteria
2.2. language evaluation criteria2.2. language evaluation criteria
2.2. language evaluation criteriaannahallare_
 
Scope - Static and Dynamic
Scope - Static and DynamicScope - Static and Dynamic
Scope - Static and DynamicSneh Pahilwani
 
Code generator
Code generatorCode generator
Code generatorTech_MX
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compilerAkhil Kaushik
 
Analysis of the source program
Analysis of the source programAnalysis of the source program
Analysis of the source programHuawei Technologies
 
compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol tablenadarmispapaulraj
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignKuppusamy P
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translationAkshaya Arunan
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysisRicha Sharma
 
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptFamiDan
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loadersTech_MX
 
Structure of the compiler
Structure of the compilerStructure of the compiler
Structure of the compilerSudhaa Ravi
 
Static and dynamic scoping
Static and dynamic scopingStatic and dynamic scoping
Static and dynamic scopingNusratShaikh16
 
Attribute grammer
Attribute grammerAttribute grammer
Attribute grammerahmed51236
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)Nitesh Singh
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - IntroductionMuhammad Sanaullah
 

Was ist angesagt? (20)

Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
2.2. language evaluation criteria
2.2. language evaluation criteria2.2. language evaluation criteria
2.2. language evaluation criteria
 
Scope - Static and Dynamic
Scope - Static and DynamicScope - Static and Dynamic
Scope - Static and Dynamic
 
Code generator
Code generatorCode generator
Code generator
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Analysis of the source program
Analysis of the source programAnalysis of the source program
Analysis of the source program
 
Semantic analysis
Semantic analysisSemantic analysis
Semantic analysis
 
compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
COMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time EnvironmentsCOMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time Environments
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.ppt
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
 
Structure of the compiler
Structure of the compilerStructure of the compiler
Structure of the compiler
 
Static and dynamic scoping
Static and dynamic scopingStatic and dynamic scoping
Static and dynamic scoping
 
Attribute grammer
Attribute grammerAttribute grammer
Attribute grammer
 
Loaders
LoadersLoaders
Loaders
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - Introduction
 

Ähnlich wie Unit 4

User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in CRAJ KUMAR
 
10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprogramsMunawar Ahmed
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdfLadallaRajKumar
 
Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on lineMilind Patil
 
chapter-7-runtime-environments.ppt
chapter-7-runtime-environments.pptchapter-7-runtime-environments.ppt
chapter-7-runtime-environments.pptssuser0db64b
 
Function in c
Function in cFunction in c
Function in cRaj Tandukar
 
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).pptxSangeetaBorde3
 
Functions in c language1
Functions in c language1Functions in c language1
Functions in c language1sirikeshava
 
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].pdfTeshaleSiyum
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdfTeshaleSiyum
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxsangeeta borde
 
Functions in Python.pdfnsjiwshkwijjahuwjwjw
Functions in Python.pdfnsjiwshkwijjahuwjwjwFunctions in Python.pdfnsjiwshkwijjahuwjwjw
Functions in Python.pdfnsjiwshkwijjahuwjwjwMayankSinghRawat6
 

Ähnlich wie 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
 

KĂŒrzlich hochgeladen

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)lakshayb543
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...Nguyen Thanh Tu Collection
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 

KĂŒrzlich hochgeladen (20)

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 

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