Question: Consider the following pseudocode: 1. procedure main() 2. a : integer := 1 3. b : integer := 2 4. procedure middle() 5. b :

Consider the following pseudocode:

1. procedure main()

2. a : integer := 1

3. b : integer := 2

4. procedure middle()

5. b : integer := a

6. procedure inner()

7. print a, b

8. a : integer := 3

9. –– body of middle

10. inner()

11. print a, b

12. –– body of main

13. middle()

14. print a, b

Suppose this was code for a language with the declaration-order rules of C (but with nested subroutines)—that is, names must be declared before use, and the scope of a name extends from its declaration through the end of the block. At each print statement, indicate which declarations of a and b are in the referencing environment. What does the program print (or will the compiler identify static semantic errors)? Repeat the exercise for the declaration-order rules of C# (names must be declared before use, but the scope of a name is the entire block in which it is declared) and ofModula-3 (names can be declared in any order, and their scope is the entire block in which they are declared).

Step by Step Solution

3.40 Rating (169 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

With C rules line 7 refers to the a and b declared on lines ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Language Pragmatics Questions!