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

Weitere ähnliche Inhalte

Was ist angesagt?

Processes and Processors in Distributed Systems
Processes and Processors in Distributed SystemsProcesses and Processors in Distributed Systems
Processes and Processors in Distributed SystemsDr Sandeep Kumar Poonia
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its typesSuraj Bora
 
Media Access Control (MAC Layer)
Media Access Control (MAC Layer)Media Access Control (MAC Layer)
Media Access Control (MAC Layer)Meenakshi Paul
 
Group Communication in distributed Systems.docx
Group Communication in distributed Systems.docxGroup Communication in distributed Systems.docx
Group Communication in distributed Systems.docxMsecMca
 
Computer Networks Unit 1 Introduction and Physical Layer
Computer Networks Unit 1 Introduction and Physical Layer Computer Networks Unit 1 Introduction and Physical Layer
Computer Networks Unit 1 Introduction and Physical Layer Dr. SELVAGANESAN S
 
Network layer - design Issues
Network layer - design IssuesNetwork layer - design Issues
Network layer - design Issuesقصي نسور
 
Assembly Language for x86 Processors 7th Edition Chapter 2 : x86 Processor Ar...
Assembly Language for x86 Processors 7th Edition Chapter 2 : x86 Processor Ar...Assembly Language for x86 Processors 7th Edition Chapter 2 : x86 Processor Ar...
Assembly Language for x86 Processors 7th Edition Chapter 2 : x86 Processor Ar...ssuser65bfce
 
RANDOM ACCESS PROTOCOL IN COMMUNICATION
RANDOM ACCESS PROTOCOL IN COMMUNICATION           RANDOM ACCESS PROTOCOL IN COMMUNICATION
RANDOM ACCESS PROTOCOL IN COMMUNICATION AMOGHA A K
 
Shared-Memory Multiprocessors
Shared-Memory MultiprocessorsShared-Memory Multiprocessors
Shared-Memory MultiprocessorsSalvatore La Bua
 
System interconnect architecture
System interconnect architectureSystem interconnect architecture
System interconnect architectureGagan Kumar
 
Unit 2 data link control
Unit 2 data link controlUnit 2 data link control
Unit 2 data link controlVishal kakade
 

Was ist angesagt? (20)

System calls
System callsSystem calls
System calls
 
Processes and Processors in Distributed Systems
Processes and Processors in Distributed SystemsProcesses and Processors in Distributed Systems
Processes and Processors in Distributed Systems
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
 
Media Access Control (MAC Layer)
Media Access Control (MAC Layer)Media Access Control (MAC Layer)
Media Access Control (MAC Layer)
 
Chapter3
Chapter3Chapter3
Chapter3
 
Group Communication in distributed Systems.docx
Group Communication in distributed Systems.docxGroup Communication in distributed Systems.docx
Group Communication in distributed Systems.docx
 
Error control
Error controlError control
Error control
 
Computer Networks Unit 1 Introduction and Physical Layer
Computer Networks Unit 1 Introduction and Physical Layer Computer Networks Unit 1 Introduction and Physical Layer
Computer Networks Unit 1 Introduction and Physical Layer
 
Network layer - design Issues
Network layer - design IssuesNetwork layer - design Issues
Network layer - design Issues
 
Assembly Language for x86 Processors 7th Edition Chapter 2 : x86 Processor Ar...
Assembly Language for x86 Processors 7th Edition Chapter 2 : x86 Processor Ar...Assembly Language for x86 Processors 7th Edition Chapter 2 : x86 Processor Ar...
Assembly Language for x86 Processors 7th Edition Chapter 2 : x86 Processor Ar...
 
generation of programming language
generation of programming languagegeneration of programming language
generation of programming language
 
RANDOM ACCESS PROTOCOL IN COMMUNICATION
RANDOM ACCESS PROTOCOL IN COMMUNICATION           RANDOM ACCESS PROTOCOL IN COMMUNICATION
RANDOM ACCESS PROTOCOL IN COMMUNICATION
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Parallel programming model
Parallel programming modelParallel programming model
Parallel programming model
 
Distributed Operating System_4
Distributed Operating System_4Distributed Operating System_4
Distributed Operating System_4
 
Shared-Memory Multiprocessors
Shared-Memory MultiprocessorsShared-Memory Multiprocessors
Shared-Memory Multiprocessors
 
Replication in Distributed Systems
Replication in Distributed SystemsReplication in Distributed Systems
Replication in Distributed Systems
 
Linker and Loader
Linker and Loader Linker and Loader
Linker and Loader
 
System interconnect architecture
System interconnect architectureSystem interconnect architecture
System interconnect architecture
 
Unit 2 data link control
Unit 2 data link controlUnit 2 data link control
Unit 2 data link control
 

Andere mochten auch

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
 

Andere mochten auch (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
 

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

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

Kürzlich hochgeladen

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 

Kürzlich hochgeladen (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.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