Sample questions to study for exam 2: 1. (20 points) Draw the abstract syntax trees that a Macro compiler would build to represent each of the following statements. (a) A := B + 5 (b) A, B, C : Integer (c) if X>2.5 then read(Y) else Y:=10.0 end if 2. (30 points) Suppose you are compiling a language that includes a IF-LOOP-UNTIL statement, which has the form: IF boolean-expression-1 LOOP statement _list UNTIL boolean-expression-2 The semantics of this statement are what would be ; next expected from the keywords: if boolean-expression-1 evaluates to True, repeatedly perform statement-list until boolean-expression-2 evaluates to True at the end of an execution of the statement list. (a) Write a production for adding this kind of statement to the Macro grammar. (b) Draw the abstract syntax tree structure that would be used to represent such a statement. (c) In pseudo-code (or C, if you wish), define the code generation operation for the tree node that represents the IF-LOOP-UNTIL statement. 3. (25 points) (a) Describe the implementation of the standard search rule for interpreting identifiers in a language that allows arbitrarily nested scopes, presuming that each scope is represented by its own symbol table. (b) In Modula-3, a set of declarations can be grouped together and named as an Interface. A Module may be defined to export a single interface (like a Macro package) or it may export multiple interfaces. (Interface definitions are syntactically separate from module definitions.) Within a module, the names declared in all of its exported interfaces are accessible just as if they were directly declared in the module itself. Explain how you would implement identifier look up from within a module body given the above rules. 4. (25 points) Consider the following procedure declarations, where nesting is indicated by indentation: procedure A procedure B procedure C procedure D procedure E After the following sequence of procedure calls: Main -> A -> D -> E -> E -> B -> C -> B -> D -> E (a) Show the state of the run-time stack and display during the execution of the final call to E. Include some indication of the value of the saved display register contained in each procedure activation record. (b) Show the static chain pointer that would be included in each activation record if a static chain were being used instead of a display.