SlideShare une entreprise Scribd logo
1  sur  7
Theory of Programming Languages
Chapter 9 & 10

Chapter 9

Review Questions:



   1. What are the three general characteristics of subprograms?
              Each subprogram has a single entry point, excluding co-routine.
              The calling program 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.
   2. What does it mean for a subprogram to be active?
              A subprogram s said to be active if, after having been called, it has begun execution but
              has not yet completed that execution.
   3. What is the parameter profile? What is subprogram protocol?
      The parameter profile of a subprogram is the number, order and types of its formal parameters.
      The protocol of subprogram is its parameter profile, if it is a function and its return type.
   4. What are formal parameters? What are actual parameters?
      The parameters in the subprogram header are called formal parameters.
      Subprogram call statements must include the name of the subprogram and alist of parameters
      to be bound to the formal parameters of the subprogram. These parameters are called actual
      parameters.
      Double sales_tax (price)
      {return 0.05 * price;}

       Tax = sales_tax(10.0);
       10.00 is actual parameter and “price” is formal parameter.

   5. What are the advantages and disadvantages of keyword parameters?
      The advantage of keyword parameter is that they can appear in any order in the actual
      parameter list.
      The disadvantage to keyword parameters is that the user of the subprogram must know the
      names of formal parameters.
   6. What are the design issues for subprograms?
          o What parameter-passing method or methods are used?
          o Are the types of the actual parameters checked against the types of the formal
              parameters?
          o Are local variable statically or dynamically allocated?
          o Can subprogram definitions appear in other subprogram definitions?
          o If subprograms can be passed as parameters and subprograms can be nested, what is
              the referencing environment of a passed subprogram?
          o Can a subprogram be overloaded?
          o Can subprograms be generic?


                                     Prepared By: Saeed Iqbal
                                    MSCS, FAST-NUCES, Peshawar
                                             P11-6501
Theory of Programming Languages
Chapter 9 & 10

   7. What are the advantages and disadvantages of dynamic local variables?
      Advantages:
                  o They provide flexibility to the subprogram
                  o The storage of local variables in an active subprogram can be shared with the
                      local variables in all inactive subprograms.
                  o They efficiently used when computer has small memory (Faster Access).
      Disadvantages:
                  o Cost of the time required to allocate
                  o Access to dynamic local variable must be indirect
                  o The stack dynamic local variables, subprograms cannot be history sensitive
   8. What are the three semantic models of parameter passing?
      The three semantic models are in mode, out mode, and in-out mode;
              In mode: they can receive data from the corresponding actual parameter.
              Out mode: they can transmit data to the actual parameter
              In-out mode: they can do both (receive data and transmit data).

   9. What are the modes, the conceptual modes of transfer, the advantages, and the
       disadvantages or pass-by-value, pass-by-result, pass-by-value-result, and pass-by-reference
       parameter-passing models?
       There are two conceptual models of how data transfers take place in parameter transmission.
       Either an actual value is copied or an access path is transmitted.
       The advantage of pass-by-value is its speed.
       The Disadvantages of pass-by-value are, when copies are used, additional storage is required.
       Storage and copy operations can be costly.
       Pass-by-result has all of the advantages and disadvantages of pass-by-value, but more
       disadvantages. An additional disadvantage is that there can be an actual parameter collision,
       because order of expressions matter.
       Pass-by-value-result has the same advantages and disadvantages as pass-by-value and pass-by-
       result with some more advantages. The largest extra advantage of pass-by-value-result is that it
       solves pass-by-reference's aliasing problems.
       An advantage of pass-by-reference is that it is efficient in both time and space.
       A disadvantage to pass-by-reference is the increase in time to access formal parameters
       because of the additional level of indirect addressing. Secondly, if only one way communication
       to the called subprogram is required, inadvertent and erroneous changes may be made to the
       actual parameter. Finally, aliasing should be expected with pass-by-reference. Since pass-by-
       reference makes access paths available to the called subprograms, it broadens their access to
       nonlocal variables. These aliasing problems lead to decreased readability and reliability.
   10. In what ways can aliases occur with pass-by-reference parameters?
       Aliases can be occurring because pass-by-reference makes access paths available to the called
       subprograms.
   11. What is the difference between the way original C and C89 deal with an actual parameter
       whose type is not identical to that of the corresponding formal parameter?
       In the Original C, neither the number of parameters not their types were checked. In C89, the
       formal parameters of functions can be defined in two ways. First they can be as in the original C;
       that is, the names of the parameters are listed in parentheses.



                                     Prepared By: Saeed Iqbal
                                    MSCS, FAST-NUCES, Peshawar
                                             P11-6501
Theory of Programming Languages
Chapter 9 & 10

   12. What is the problem with Ada’s policy of following implementers to decide which parameters
       to pass-by-reference and which to pass-by-value-result.?
   13. What are two fundamental design considerations for parameter-passing methods?
       Two important considerations are involved in choosing parameter-passing methods: efficiency
       and whether one-way or two-way data transfer is needed.
       In-mode parameters should be used whenever no data are to be returned through parameters
       to the caller. Out-mode parameters should be used when no data are transferred to the called
       subprogram. In-Out mode parameters should be used only when data must move in both
       directions between the caller and the called subprogram.
   14. What are the two issues that arise when subprogram names are parameters?
       The first issue that arises is type checking the parameters of the activations of the subprogram
       that was passed as a parameter.
       The second complication appears in languages that allow nested subprograms. There is another
       issue related to subprogram names that are passed as parameters. The question is what
       referencing environment for executing the pass subprogram should be used.
   15. Define Shallow and deep binding for referencing environment of subprograms that have been
       passed as parameters?
       The environment of the call statement that enacts the passed subprogram is the environment
       for the passing subprogram. This is called shallow binding.
       The environment of the definition of the passed subprogram is the environment of the passing
       subprogram. This is called deep binding.
   16. What is overloaded subprogram?
       Overloaded subprogram is a subprogram that has the same name as another subprogram in the
       same referencing environment
   17. What is parametric polymorphism?
       Parametric polymorphism is provided by a subprogram that takes a generic parameter that is
       used in a type expression that describes the types of the parameters of the subprogram. Both
       Ada and C++ provides a kind of compile-time parametric polymorphism.
   18. What causes a C++ template function to be instantiated?
       C++ template functions are instantiated implicitly either when the function is named in a call or
       when its address is taken with the & processor.
   19. In what fundamental way do the generic parameters to a Java 5.0 generic methoddiffer from
       those of C++ methods?
       Java does not use objects exclusively, java have no enumeration or record type. Whereas C++
       Classes can be defined to have no parent, that is not possible in Java. All Java Classes must be
       subclass of the root class.
   20. If a Java 5.0 method returns a generic type, what type of object is actually returned?
       In Java any type or class can be returned by methods. Because methods are not types, they
       cannot be returned.
   21. If a Java5.0 generic method is called with three different generic parameters, how many
       versions of the method will be generated by the compiler?
   22. What are the design issues for functions?
       Two design issues are functions.
                i.       Are side effects allowed?
                ii.      What types of values can be returned?
   23. In what ways are coroutines different from conventional subprogram?


                                     Prepared By: Saeed Iqbal
                                    MSCS, FAST-NUCES, Peshawar
                                             P11-6501
Theory of Programming Languages
Chapter 9 & 10

       Conventional subprograms are subordinate to their callers. When a routine calls a subprogram,
       execution suspends at that point in the program and resumes after the subprogram has run to
       completion. As a result, conventional subprogram invocation is atomic, much like a built-in
       statement in the programming language.




                                    Prepared By: Saeed Iqbal
                                   MSCS, FAST-NUCES, Peshawar
                                            P11-6501
Theory of Programming Languages
Chapter 9 & 10


       Chapter 10
       Review Questions:

       1. What are the two reasons why implementing subprograms with stack-dynamic local
          variables is more difficult than implementing simple sub-programs?
                  A stack-dynamic local variable is more complex activation records. The compiler
                  must generate code to cause implicit allocation and de-allocation of local variables
                  Recursion must be supported (adds the possibility of multiple simultaneous
                  activations of a subprogram).
       2. What is the difference between an activation record and activation record instance?
          The Format, or layout, of the non-code part of a subprogram is called an activation record.
          An activation record stores all the information about subprogram calls,activation records
          stores the following data (in the following order)
                            Return address
                            Static link – to the static parent (where the subprogram is declared).
                            Dynamic link – to the caller of this subprogram.
                            Parameters
                            Local variables.
       3. Why are the return address, dynamic link, and parameters placed in the bottom of the
          activation record?
          Ans: ?
       4. What are the two steps in locating a nonlocal variable in a static-scoped language with
          stack-dynamic local variables and nested subprograms?
              Find the correct activation record instance
              Determine the correct offset within that activation record instance

       5. Define static chain, static depth, nesting_depth, and chain offset.
          A static chain is a chain of static links that connects certain activation record instances
          Static_depth is an integer associated with a static scope representing the scope’s nesting
          depth
          The chain_offset or nesting_depth of a non-local reference is the difference between the
          static_depth of the reference and that of the scope where it is declared

       6. What are the two potential problems with the static chain methods?
            A nonlocal reference is slow if the number of scopes between the reference and the
            declaration of the referenced variable is large
            Time-critical code is difficult, because the costs of nonlocal references are not equal,
            and can change with code upgrades and fixes

       7. What is display?
          One alternative to static chain is to use a display, for this approach, the static links are
          collected in a single array called a display. Display uses a pointer array to store the activation
          records along the static chain.




                                      Prepared By: Saeed Iqbal
                                     MSCS, FAST-NUCES, Peshawar
                                              P11-6501
Theory of Programming Languages
Chapter 9 & 10

       8. Explain how areference to a nonlocal variable is found when a display is used?
          Access to nonlocal variables using a display requires two steps for every access. First the link
          to the correct activation record, which resides in the display, is found using a statically
          computed value called the display offset. The local offset within the activation record
          instance is computed and used exactly as with static chain implementations. A nonlocal
          reference is represented by an ordered pair of integer (display offset and local offset)

       9. How are references to variables represented in the static chain method?
          This chain can obviously be used to implement the access to non-local variables in static-
          scoped languages.
          When a reference is made to a non-local variable, the ARI containing the variable can be
          found by searching the static chain until a static ancestor ARI is found that contains the
          variable.
          Because the nesting scope is known at compile time, the compiler can determine not only
          that a reference is non-local but also the length of the static chain must be followed to reach
          the ARI that contains the non-local object.

       10. Explain the two methods of implementing block?
           Blocks are treated as parameter less subprograms that are always called from the same
           place in the program.
           Block can also be implemented in a different and somewhat simpler and more efficient way.
           The maximum amount of storage required for block variables at any time during the
           exaction of program can be statically determined, because block are entered and exited in
           strictly textual order.

       11. Describe the deep access method of implementing dynamic scoping?
           Deep Access - nonlocal references are found by searching the activation record instances on
           the dynamic chain. Length of chain cannot be statically determined every activation record
           instance must have variable names

       12. Describe the shallow access method of implementing dynamic scoping?
           In case of shallow access names and values are stored in a global table. Using this method,
           space is allocated for every variable name that is in the program (one space for variable
           temp though there might be several declarations of temp in the different methods). When a
           sub-routine is called it saves the current value of the variable and replaces it with the value
           in its current scope and restores the value of the variable while exiting.

       13. What are the two differences between the deep access method for non-local access in
           dynamic-scoped languages and the static chain method for static scoped languages?
           Deep Access method for nonlocal access is found bysearching the activation record
           instances of other subprograms that are currently active, beginning with the one most
           recently activated.
           In static Chain, Compiler simply passes the link to the Static parameter, along with the
           parameter.




                                      Prepared By: Saeed Iqbal
                                     MSCS, FAST-NUCES, Peshawar
                                              P11-6501
Theory of Programming Languages
Chapter 9 & 10

       14. Compare the efficiency of the deep access method to that of the shallow access method,
           in term of both call and nonlocal access?
           The deep access methods provides fast subprogram linkage, but references to nonlocal,
           especially references to distant nonlocals (in term of the call chain), are costly. The shallow
           access methods provide much faster references to nonlocals, especially distant nonlocals,
           but are more costly in term of subprogram linkage.




                                      Prepared By: Saeed Iqbal
                                     MSCS, FAST-NUCES, Peshawar
                                              P11-6501

Contenu connexe

Tendances

Introduction to Software Project Management
Introduction to Software Project ManagementIntroduction to Software Project Management
Introduction to Software Project ManagementReetesh Gupta
 
Concepts of Programming Languages 10th Edition Robert W. Sebesta Solutions Ma...
Concepts of Programming Languages 10th Edition Robert W. Sebesta Solutions Ma...Concepts of Programming Languages 10th Edition Robert W. Sebesta Solutions Ma...
Concepts of Programming Languages 10th Edition Robert W. Sebesta Solutions Ma...javan013
 
Ch2-Software Engineering 9
Ch2-Software Engineering 9Ch2-Software Engineering 9
Ch2-Software Engineering 9Ian Sommerville
 
distributed Computing system model
distributed Computing system modeldistributed Computing system model
distributed Computing system modelHarshad Umredkar
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos conceptsanishgoel
 
Spiral model
Spiral modelSpiral model
Spiral modelkhuram22
 
Chapter 7 software reliability
Chapter 7 software reliabilityChapter 7 software reliability
Chapter 7 software reliabilitydespicable me
 
Software Engineering Past Papers (Short Questions)
Software Engineering Past Papers (Short Questions)Software Engineering Past Papers (Short Questions)
Software Engineering Past Papers (Short Questions)MuhammadTalha436
 
Software Engineering Solved Past Paper 2020
Software Engineering Solved Past Paper 2020 Software Engineering Solved Past Paper 2020
Software Engineering Solved Past Paper 2020 MuhammadTalha436
 
Requirement specification (SRS)
Requirement specification (SRS)Requirement specification (SRS)
Requirement specification (SRS)kunj desai
 
Ds objects and models
Ds objects and modelsDs objects and models
Ds objects and modelsMayank Jain
 
Evolutionary process models se.ppt
Evolutionary process models se.pptEvolutionary process models se.ppt
Evolutionary process models se.pptbhadjaashvini1
 
Waterfall model and spiral model
Waterfall model and spiral modelWaterfall model and spiral model
Waterfall model and spiral modelShirisha Maharjan
 
Unit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - ThreadsUnit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - Threadscscarcas
 
Task communication
Task communicationTask communication
Task communication1jayanti
 
Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorialcscarcas
 
MG6088 SOFTWARE PROJECT MANAGEMENT
MG6088 SOFTWARE PROJECT MANAGEMENTMG6088 SOFTWARE PROJECT MANAGEMENT
MG6088 SOFTWARE PROJECT MANAGEMENTKathirvel Ayyaswamy
 

Tendances (20)

Introduction to Software Project Management
Introduction to Software Project ManagementIntroduction to Software Project Management
Introduction to Software Project Management
 
Concepts of Programming Languages 10th Edition Robert W. Sebesta Solutions Ma...
Concepts of Programming Languages 10th Edition Robert W. Sebesta Solutions Ma...Concepts of Programming Languages 10th Edition Robert W. Sebesta Solutions Ma...
Concepts of Programming Languages 10th Edition Robert W. Sebesta Solutions Ma...
 
Ch2-Software Engineering 9
Ch2-Software Engineering 9Ch2-Software Engineering 9
Ch2-Software Engineering 9
 
distributed Computing system model
distributed Computing system modeldistributed Computing system model
distributed Computing system model
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos concepts
 
Ch23 project planning
Ch23 project planningCh23 project planning
Ch23 project planning
 
Ch4 req eng
Ch4 req engCh4 req eng
Ch4 req eng
 
Spiral model
Spiral modelSpiral model
Spiral model
 
Chapter 7 software reliability
Chapter 7 software reliabilityChapter 7 software reliability
Chapter 7 software reliability
 
Software Engineering Past Papers (Short Questions)
Software Engineering Past Papers (Short Questions)Software Engineering Past Papers (Short Questions)
Software Engineering Past Papers (Short Questions)
 
Software Engineering Solved Past Paper 2020
Software Engineering Solved Past Paper 2020 Software Engineering Solved Past Paper 2020
Software Engineering Solved Past Paper 2020
 
Requirement specification (SRS)
Requirement specification (SRS)Requirement specification (SRS)
Requirement specification (SRS)
 
Ds objects and models
Ds objects and modelsDs objects and models
Ds objects and models
 
Grasp
GraspGrasp
Grasp
 
Evolutionary process models se.ppt
Evolutionary process models se.pptEvolutionary process models se.ppt
Evolutionary process models se.ppt
 
Waterfall model and spiral model
Waterfall model and spiral modelWaterfall model and spiral model
Waterfall model and spiral model
 
Unit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - ThreadsUnit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - Threads
 
Task communication
Task communicationTask communication
Task communication
 
Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorial
 
MG6088 SOFTWARE PROJECT MANAGEMENT
MG6088 SOFTWARE PROJECT MANAGEMENTMG6088 SOFTWARE PROJECT MANAGEMENT
MG6088 SOFTWARE PROJECT MANAGEMENT
 

En vedette

Chapter 9 – homework
Chapter 9 – homeworkChapter 9 – homework
Chapter 9 – homeworkbagarza
 
Hibbeler chapter10
Hibbeler chapter10Hibbeler chapter10
Hibbeler chapter10ahmedalnamer
 
[W f stoecker]_refrigeration_and_a_ir_conditioning_(book_zz.org)
[W f stoecker]_refrigeration_and_a_ir_conditioning_(book_zz.org)[W f stoecker]_refrigeration_and_a_ir_conditioning_(book_zz.org)
[W f stoecker]_refrigeration_and_a_ir_conditioning_(book_zz.org)Mike Mentzos
 
Scope - Static and Dynamic
Scope - Static and DynamicScope - Static and Dynamic
Scope - Static and DynamicSneh Pahilwani
 
Refrigeration and-air-conditioning-notes
Refrigeration and-air-conditioning-notesRefrigeration and-air-conditioning-notes
Refrigeration and-air-conditioning-notesOlumide Daniel
 
Notes from Sebesta
Notes from SebestaNotes from Sebesta
Notes from SebestaCS, NcState
 
Stoecker _jones_-_refrigeration___air_conditioning_2nd_ed__mcgraw_hill_
Stoecker  _jones_-_refrigeration___air_conditioning_2nd_ed__mcgraw_hill_Stoecker  _jones_-_refrigeration___air_conditioning_2nd_ed__mcgraw_hill_
Stoecker _jones_-_refrigeration___air_conditioning_2nd_ed__mcgraw_hill_Auzi Faiz Bahtiar
 
How to build a news website use CMS wordpress
How to build a news website use CMS wordpressHow to build a news website use CMS wordpress
How to build a news website use CMS wordpressbaran19901990
 
09 implementing+subprograms
09 implementing+subprograms09 implementing+subprograms
09 implementing+subprogramsbaran19901990
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentationbaran19901990
 
Nhập môn công tác kỹ sư
Nhập môn công tác kỹ sưNhập môn công tác kỹ sư
Nhập môn công tác kỹ sưbaran19901990
 
Config websocket on apache
Config websocket on apacheConfig websocket on apache
Config websocket on apachebaran19901990
 
Memory allocation
Memory allocationMemory allocation
Memory allocationsanya6900
 

En vedette (20)

Chapter 9 – homework
Chapter 9 – homeworkChapter 9 – homework
Chapter 9 – homework
 
Hibbeler chapter10
Hibbeler chapter10Hibbeler chapter10
Hibbeler chapter10
 
[W f stoecker]_refrigeration_and_a_ir_conditioning_(book_zz.org)
[W f stoecker]_refrigeration_and_a_ir_conditioning_(book_zz.org)[W f stoecker]_refrigeration_and_a_ir_conditioning_(book_zz.org)
[W f stoecker]_refrigeration_and_a_ir_conditioning_(book_zz.org)
 
Chapter2
Chapter2Chapter2
Chapter2
 
Scope - Static and Dynamic
Scope - Static and DynamicScope - Static and Dynamic
Scope - Static and Dynamic
 
Unit 5
Unit 5Unit 5
Unit 5
 
Refrigeration and-air-conditioning-notes
Refrigeration and-air-conditioning-notesRefrigeration and-air-conditioning-notes
Refrigeration and-air-conditioning-notes
 
Notes from Sebesta
Notes from SebestaNotes from Sebesta
Notes from Sebesta
 
Stoecker _jones_-_refrigeration___air_conditioning_2nd_ed__mcgraw_hill_
Stoecker  _jones_-_refrigeration___air_conditioning_2nd_ed__mcgraw_hill_Stoecker  _jones_-_refrigeration___air_conditioning_2nd_ed__mcgraw_hill_
Stoecker _jones_-_refrigeration___air_conditioning_2nd_ed__mcgraw_hill_
 
How to build a news website use CMS wordpress
How to build a news website use CMS wordpressHow to build a news website use CMS wordpress
How to build a news website use CMS wordpress
 
Hadoop
HadoopHadoop
Hadoop
 
09 implementing+subprograms
09 implementing+subprograms09 implementing+subprograms
09 implementing+subprograms
 
Introduction to HBase
Introduction to HBaseIntroduction to HBase
Introduction to HBase
 
08 subprograms
08 subprograms08 subprograms
08 subprograms
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
 
Datatype
DatatypeDatatype
Datatype
 
Nhập môn công tác kỹ sư
Nhập môn công tác kỹ sưNhập môn công tác kỹ sư
Nhập môn công tác kỹ sư
 
Config websocket on apache
Config websocket on apacheConfig websocket on apache
Config websocket on apache
 
Control structure
Control structureControl structure
Control structure
 
Memory allocation
Memory allocationMemory allocation
Memory allocation
 

Similaire à Chapter 9 & chapter 10 solutions

Frequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answersFrequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answersnishajj
 
Bca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroductionBca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroductionRai University
 
Mca 2 sem u-1 iintroduction
Mca 2 sem u-1 iintroductionMca 2 sem u-1 iintroduction
Mca 2 sem u-1 iintroductionRai University
 
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...Raffi Khatchadourian
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural ProgrammingDeepam Aggarwal
 
Initial Architectural Design (Game Architecture)
Initial Architectural Design (Game Architecture)Initial Architectural Design (Game Architecture)
Initial Architectural Design (Game Architecture)Rajkumar Pawar
 
Tcs NQTExam technical questions
Tcs NQTExam technical questionsTcs NQTExam technical questions
Tcs NQTExam technical questionsAniketBhandare2
 
Technical_Interview_Questions.pdf
Technical_Interview_Questions.pdfTechnical_Interview_Questions.pdf
Technical_Interview_Questions.pdfadityashukla939020
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview QuestionsSyed Shahul
 
Hibernate reference1
Hibernate reference1Hibernate reference1
Hibernate reference1chandra mouli
 
Hibernate interview questions
Hibernate interview questionsHibernate interview questions
Hibernate interview questionsvenkata52
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerJeba Moses
 

Similaire à Chapter 9 & chapter 10 solutions (20)

Unit 2
Unit 2Unit 2
Unit 2
 
Csci360 08-subprograms
Csci360 08-subprogramsCsci360 08-subprograms
Csci360 08-subprograms
 
Frequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answersFrequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answers
 
Subprogramms
SubprogrammsSubprogramms
Subprogramms
 
Bca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroductionBca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroduction
 
Mca 2 sem u-1 iintroduction
Mca 2 sem u-1 iintroductionMca 2 sem u-1 iintroduction
Mca 2 sem u-1 iintroduction
 
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural Programming
 
Initial Architectural Design (Game Architecture)
Initial Architectural Design (Game Architecture)Initial Architectural Design (Game Architecture)
Initial Architectural Design (Game Architecture)
 
Tcs NQTExam technical questions
Tcs NQTExam technical questionsTcs NQTExam technical questions
Tcs NQTExam technical questions
 
Technical_Interview_Questions.pdf
Technical_Interview_Questions.pdfTechnical_Interview_Questions.pdf
Technical_Interview_Questions.pdf
 
Training 8051Report
Training 8051ReportTraining 8051Report
Training 8051Report
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
 
Hibernate reference1
Hibernate reference1Hibernate reference1
Hibernate reference1
 
Unit 1
Unit  1Unit  1
Unit 1
 
Hibernate interview questions
Hibernate interview questionsHibernate interview questions
Hibernate interview questions
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
 
Unit iii for PG PAWSN
Unit iii for PG PAWSNUnit iii for PG PAWSN
Unit iii for PG PAWSN
 
14274730 (1).ppt
14274730 (1).ppt14274730 (1).ppt
14274730 (1).ppt
 
Question bank unit i
Question bank unit iQuestion bank unit i
Question bank unit i
 

Dernier

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 

Dernier (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

Chapter 9 & chapter 10 solutions

  • 1. Theory of Programming Languages Chapter 9 & 10 Chapter 9 Review Questions: 1. What are the three general characteristics of subprograms? Each subprogram has a single entry point, excluding co-routine. The calling program 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. 2. What does it mean for a subprogram to be active? A subprogram s said to be active if, after having been called, it has begun execution but has not yet completed that execution. 3. What is the parameter profile? What is subprogram protocol? The parameter profile of a subprogram is the number, order and types of its formal parameters. The protocol of subprogram is its parameter profile, if it is a function and its return type. 4. What are formal parameters? What are actual parameters? The parameters in the subprogram header are called formal parameters. Subprogram call statements must include the name of the subprogram and alist of parameters to be bound to the formal parameters of the subprogram. These parameters are called actual parameters. Double sales_tax (price) {return 0.05 * price;} Tax = sales_tax(10.0); 10.00 is actual parameter and “price” is formal parameter. 5. What are the advantages and disadvantages of keyword parameters? The advantage of keyword parameter is that they can appear in any order in the actual parameter list. The disadvantage to keyword parameters is that the user of the subprogram must know the names of formal parameters. 6. What are the design issues for subprograms? o What parameter-passing method or methods are used? o Are the types of the actual parameters checked against the types of the formal parameters? o Are local variable statically or dynamically allocated? o Can subprogram definitions appear in other subprogram definitions? o If subprograms can be passed as parameters and subprograms can be nested, what is the referencing environment of a passed subprogram? o Can a subprogram be overloaded? o Can subprograms be generic? Prepared By: Saeed Iqbal MSCS, FAST-NUCES, Peshawar P11-6501
  • 2. Theory of Programming Languages Chapter 9 & 10 7. What are the advantages and disadvantages of dynamic local variables? Advantages: o They provide flexibility to the subprogram o The storage of local variables in an active subprogram can be shared with the local variables in all inactive subprograms. o They efficiently used when computer has small memory (Faster Access). Disadvantages: o Cost of the time required to allocate o Access to dynamic local variable must be indirect o The stack dynamic local variables, subprograms cannot be history sensitive 8. What are the three semantic models of parameter passing? The three semantic models are in mode, out mode, and in-out mode; In mode: they can receive data from the corresponding actual parameter. Out mode: they can transmit data to the actual parameter In-out mode: they can do both (receive data and transmit data). 9. What are the modes, the conceptual modes of transfer, the advantages, and the disadvantages or pass-by-value, pass-by-result, pass-by-value-result, and pass-by-reference parameter-passing models? There are two conceptual models of how data transfers take place in parameter transmission. Either an actual value is copied or an access path is transmitted. The advantage of pass-by-value is its speed. The Disadvantages of pass-by-value are, when copies are used, additional storage is required. Storage and copy operations can be costly. Pass-by-result has all of the advantages and disadvantages of pass-by-value, but more disadvantages. An additional disadvantage is that there can be an actual parameter collision, because order of expressions matter. Pass-by-value-result has the same advantages and disadvantages as pass-by-value and pass-by- result with some more advantages. The largest extra advantage of pass-by-value-result is that it solves pass-by-reference's aliasing problems. An advantage of pass-by-reference is that it is efficient in both time and space. A disadvantage to pass-by-reference is the increase in time to access formal parameters because of the additional level of indirect addressing. Secondly, if only one way communication to the called subprogram is required, inadvertent and erroneous changes may be made to the actual parameter. Finally, aliasing should be expected with pass-by-reference. Since pass-by- reference makes access paths available to the called subprograms, it broadens their access to nonlocal variables. These aliasing problems lead to decreased readability and reliability. 10. In what ways can aliases occur with pass-by-reference parameters? Aliases can be occurring because pass-by-reference makes access paths available to the called subprograms. 11. What is the difference between the way original C and C89 deal with an actual parameter whose type is not identical to that of the corresponding formal parameter? In the Original C, neither the number of parameters not their types were checked. In C89, the formal parameters of functions can be defined in two ways. First they can be as in the original C; that is, the names of the parameters are listed in parentheses. Prepared By: Saeed Iqbal MSCS, FAST-NUCES, Peshawar P11-6501
  • 3. Theory of Programming Languages Chapter 9 & 10 12. What is the problem with Ada’s policy of following implementers to decide which parameters to pass-by-reference and which to pass-by-value-result.? 13. What are two fundamental design considerations for parameter-passing methods? Two important considerations are involved in choosing parameter-passing methods: efficiency and whether one-way or two-way data transfer is needed. In-mode parameters should be used whenever no data are to be returned through parameters to the caller. Out-mode parameters should be used when no data are transferred to the called subprogram. In-Out mode parameters should be used only when data must move in both directions between the caller and the called subprogram. 14. What are the two issues that arise when subprogram names are parameters? The first issue that arises is type checking the parameters of the activations of the subprogram that was passed as a parameter. The second complication appears in languages that allow nested subprograms. There is another issue related to subprogram names that are passed as parameters. The question is what referencing environment for executing the pass subprogram should be used. 15. Define Shallow and deep binding for referencing environment of subprograms that have been passed as parameters? The environment of the call statement that enacts the passed subprogram is the environment for the passing subprogram. This is called shallow binding. The environment of the definition of the passed subprogram is the environment of the passing subprogram. This is called deep binding. 16. What is overloaded subprogram? Overloaded subprogram is a subprogram that has the same name as another subprogram in the same referencing environment 17. What is parametric polymorphism? Parametric polymorphism is provided by a subprogram that takes a generic parameter that is used in a type expression that describes the types of the parameters of the subprogram. Both Ada and C++ provides a kind of compile-time parametric polymorphism. 18. What causes a C++ template function to be instantiated? C++ template functions are instantiated implicitly either when the function is named in a call or when its address is taken with the & processor. 19. In what fundamental way do the generic parameters to a Java 5.0 generic methoddiffer from those of C++ methods? Java does not use objects exclusively, java have no enumeration or record type. Whereas C++ Classes can be defined to have no parent, that is not possible in Java. All Java Classes must be subclass of the root class. 20. If a Java 5.0 method returns a generic type, what type of object is actually returned? In Java any type or class can be returned by methods. Because methods are not types, they cannot be returned. 21. If a Java5.0 generic method is called with three different generic parameters, how many versions of the method will be generated by the compiler? 22. What are the design issues for functions? Two design issues are functions. i. Are side effects allowed? ii. What types of values can be returned? 23. In what ways are coroutines different from conventional subprogram? Prepared By: Saeed Iqbal MSCS, FAST-NUCES, Peshawar P11-6501
  • 4. Theory of Programming Languages Chapter 9 & 10 Conventional subprograms are subordinate to their callers. When a routine calls a subprogram, execution suspends at that point in the program and resumes after the subprogram has run to completion. As a result, conventional subprogram invocation is atomic, much like a built-in statement in the programming language. Prepared By: Saeed Iqbal MSCS, FAST-NUCES, Peshawar P11-6501
  • 5. Theory of Programming Languages Chapter 9 & 10 Chapter 10 Review Questions: 1. What are the two reasons why implementing subprograms with stack-dynamic local variables is more difficult than implementing simple sub-programs? A stack-dynamic local variable is more complex activation records. The compiler must generate code to cause implicit allocation and de-allocation of local variables Recursion must be supported (adds the possibility of multiple simultaneous activations of a subprogram). 2. What is the difference between an activation record and activation record instance? The Format, or layout, of the non-code part of a subprogram is called an activation record. An activation record stores all the information about subprogram calls,activation records stores the following data (in the following order) Return address Static link – to the static parent (where the subprogram is declared). Dynamic link – to the caller of this subprogram. Parameters Local variables. 3. Why are the return address, dynamic link, and parameters placed in the bottom of the activation record? Ans: ? 4. What are the two steps in locating a nonlocal variable in a static-scoped language with stack-dynamic local variables and nested subprograms? Find the correct activation record instance Determine the correct offset within that activation record instance 5. Define static chain, static depth, nesting_depth, and chain offset. A static chain is a chain of static links that connects certain activation record instances Static_depth is an integer associated with a static scope representing the scope’s nesting depth The chain_offset or nesting_depth of a non-local reference is the difference between the static_depth of the reference and that of the scope where it is declared 6. What are the two potential problems with the static chain methods? A nonlocal reference is slow if the number of scopes between the reference and the declaration of the referenced variable is large Time-critical code is difficult, because the costs of nonlocal references are not equal, and can change with code upgrades and fixes 7. What is display? One alternative to static chain is to use a display, for this approach, the static links are collected in a single array called a display. Display uses a pointer array to store the activation records along the static chain. Prepared By: Saeed Iqbal MSCS, FAST-NUCES, Peshawar P11-6501
  • 6. Theory of Programming Languages Chapter 9 & 10 8. Explain how areference to a nonlocal variable is found when a display is used? Access to nonlocal variables using a display requires two steps for every access. First the link to the correct activation record, which resides in the display, is found using a statically computed value called the display offset. The local offset within the activation record instance is computed and used exactly as with static chain implementations. A nonlocal reference is represented by an ordered pair of integer (display offset and local offset) 9. How are references to variables represented in the static chain method? This chain can obviously be used to implement the access to non-local variables in static- scoped languages. When a reference is made to a non-local variable, the ARI containing the variable can be found by searching the static chain until a static ancestor ARI is found that contains the variable. Because the nesting scope is known at compile time, the compiler can determine not only that a reference is non-local but also the length of the static chain must be followed to reach the ARI that contains the non-local object. 10. Explain the two methods of implementing block? Blocks are treated as parameter less subprograms that are always called from the same place in the program. Block can also be implemented in a different and somewhat simpler and more efficient way. The maximum amount of storage required for block variables at any time during the exaction of program can be statically determined, because block are entered and exited in strictly textual order. 11. Describe the deep access method of implementing dynamic scoping? Deep Access - nonlocal references are found by searching the activation record instances on the dynamic chain. Length of chain cannot be statically determined every activation record instance must have variable names 12. Describe the shallow access method of implementing dynamic scoping? In case of shallow access names and values are stored in a global table. Using this method, space is allocated for every variable name that is in the program (one space for variable temp though there might be several declarations of temp in the different methods). When a sub-routine is called it saves the current value of the variable and replaces it with the value in its current scope and restores the value of the variable while exiting. 13. What are the two differences between the deep access method for non-local access in dynamic-scoped languages and the static chain method for static scoped languages? Deep Access method for nonlocal access is found bysearching the activation record instances of other subprograms that are currently active, beginning with the one most recently activated. In static Chain, Compiler simply passes the link to the Static parameter, along with the parameter. Prepared By: Saeed Iqbal MSCS, FAST-NUCES, Peshawar P11-6501
  • 7. Theory of Programming Languages Chapter 9 & 10 14. Compare the efficiency of the deep access method to that of the shallow access method, in term of both call and nonlocal access? The deep access methods provides fast subprogram linkage, but references to nonlocal, especially references to distant nonlocals (in term of the call chain), are costly. The shallow access methods provide much faster references to nonlocals, especially distant nonlocals, but are more costly in term of subprogram linkage. Prepared By: Saeed Iqbal MSCS, FAST-NUCES, Peshawar P11-6501