Note: I am not providing all details - please work these out on your own. If you have any questions, contact me via email. If you need a meeting time, we can meet on Monday - just email me in advance to arrange a meeting time. Keep in mind that these are not the only possible solutions. === Q1: Use a synthesized attribute of type "List of INT/BOOL" for . Use a similar attribute for , but here the list will always be of size 1. At production ::= , 1 concatenate the lists for the two children === Q2: Use an inherited attribute expTypes for , of type "List of INT/BOOL". At production ::= , 1 need a check Cond: size(.expTypes) > 1 The tail of the list is sent down to 1. The head of the list is sent down to as some inherited attribute (e.g. .expType) where it is used for type checking. At production ::= need a check Cond: size(.expTypes) = 1 === Q3: In the grammar discussed in class, for production ::= begin ; end we have .alltbl := push(.tbl, .alltbl) In the changed grammar, we need .alltbl := .alltbl At production 1 ::= ;2 we can have 2.alltbl := push(.tbl, 1.alltbl) Which will create a new entry on top of the stack: a symbol table with one entry in it. Exactly the same rule can be applied for .alltbl If the is a function declaration, typechecking of the function body will consider all declarations before the function, including the function declaration itself (this is needed for typechecking of recursive functions). === Q4: At each node, compute a set of triples of string (x,y,z) such that x:=y+z appeared earlier, and x/y/z are not modified since. There are many ways to do this: e.g. Inherited attribute .triples Inherited attribute .triples_in Synthesized attribute .triples_out At production 1 ::= 2, have .triples_in := 1.triples 2.triples := .triples_out If is an assignment id:=const, .triples_out is obtained from .triples_in by removing any triples that contain id.lexval. If is an assignment id1:=id2+id3, .triples_out is obtained from .triples_in by first removing any triples that contain id1.lexval, and then adding the triple (id1.lexval,id2.lexval,id3.lexval) Part 2: The key question is how to update triples_out when the statement is . Since the assignment may execute, we still have to "kill" any triples in triples_in that contain the variable on the left-hand side of the conditional assignment. For example, a synthesized attribute for and can be used to propagate the string name of this left-hand-size variable. === Q5: If you understand how the if-then-else and while-do constructs are handled (as described in the lecture notes), you should not have any problems with this question - the solution is straightforward.