P ::= declare Decl begin Stmt end Decl ::= [empty] Decl ::= identifier : Integer ; Decl Stmt ::= [empty] Stmt ::= identifier := 3 ; StmtYou may choose relatively complex attributes, like sets of identifiers. P must have a synthesized attribute check which is true if and only if every variable used (found in an assigment statement) is delcared.
function S (x: integer): booleanand will return true exactly when the argument is in the set S. In a language like Pascal where functions can be passed as arguments it is possible to represent sets of sets. This makes it possible to try to represent the set R given above. Hint: This problem has nothing to do with the set data type of Pascal.
declare x: Integer := y; y: Integer := 1; begin -- Print x and y end;Here is the same situation in Modula-3.
VAR x: INTEGER := y; y: INTEGER := 1; BEGIN (* Print x and y. *) ENDWhat do you think happens when you compile the Ada program? What do you think happens when you run the Modula-3 program? What is the difference in scope rules? Explain the advantages and disadvantages of each approach.
For the brave, what happens when you compile and run the Java programs below? Answer questions 1, 2, and 3 in the programs below and explain. Java acts like Ada in this example:
class A { static int x = y; // (1) Is y visible here? static int y = 1; static { /* Print x and y */ } }But you can get the Modula-3 behavior indirectly, because the scope rules in Java for classes and methods are different than those for simple class variables in Java. Consider:
class Order { static int y = Later.y; // (2) Is Later (and y) visible here? } class Later { static int x = Order.y; static int y = 1; static { /* Print x and y */ } }The order in which the classes Order and Later are declared makes no difference. Or an entirely different Java example:
class Three { static int gety () {return y;} // (3) Is y visible here? static int x = gety(); static int y = 1; static { /* Print x and y */ } }