Midterm CSU 670 Fall 2005 Karl Lieberherr YOUR NAME Put your name on every answer sheet Question 1: I use the following process: 1. Create new directory called parser and use "demeterj new" 2. put g1 into program.cd 3. Modify program.beh as follows: Main { {{ public static void main(String args[]) throws Exception { SPL m = SPL.parse(System.in); m.print(); }} } SPL { void print() to * (PrintVisitor); } Put input into program.input demeterj test cd .. mkdir printer cd printer demeterj new put g2 into program.cd demeterj test cd .. cp printer/gen/PrintVisitor.java parser/gen/PrintVisitor.java cd parser demeterj test echo "This was the translated SPL input" The parser directory contains the translator. This process works because the two class dictionaries g1 and g2 have the same structure. That is they are identical modulo the tokens; in other words, when we delete all tokens " ... " from g1 and g2, then g1 and g2 are the same. Can also be done with a visitor. But is longer and more error prone. For "=" and "else" need edge visitor. Or it can be done writing a recursive print method from scratch. Again longer and more error prone. Question 2: ================================================== UNKNOWN1 = ClassGraph UNKNOWN2 = parse UNKNOWN3 = ClassGraph UNKNOWN4 = this UNKNOWN5 = SPL UNKNOWN6 = Block UNKNOWN7 = dep = 0 UNKNOWN8 = Block UNKNOWN9 = dep ++ UNKNOWN10 = Block Question 3: ================================================== UNKNOWN1 = Block UNKNOWN2 = Declaration_List UNKNOWN3 = Declaration UNKNOWN4 = Inte UNKNOWN5 = x UNKNOWN6 = Numbe UNKNOWN7 = 10 UNKNOWN8 = Declaration UNKNOWN9 = Bool UNKNOWN10 = Variable UNKNOWN11 = b UNKNOWN12 = Compound UNKNOWN13 = Numbe UNKNOWN14 = 0 UNKNOWN15 = GT UNKNOWN16 = Numbe UNKNOWN17 = 0 UNKNOWN18 = Assignment UNKNOWN19 = Variable UNKNOWN20 = x UNKNOWN21 = Numbe UNKNOWN22 = 11 UNKNOWN23 = WhileStat UNKNOWN24 = Variable UNKNOWN25 = b UNKNOWN26 = Block UNKNOWN27 = Assignment UNKNOWN28 = Variable UNKNOWN29 = x UNKNOWN30 = Variable UNKNOWN31 = x Question 4 =========================================================== Question 4.1 Parenthesize List. Container = List(Item) Capacity Weight. Item : Simple | Container common Weight. Weight = int. Simple = . Capacity = int. List(S) ~ "(" {S} ")". Question 4.2 Container = "container" List(Item) Capacity Weight. Item : Simple | Container common Weight. Weight = int. Simple : Apple | Orange. Apple = "apple". Orange = "orange". Capacity = int. List(S) ~ {S}. Question 4.3 A = List(B). B = List(C). C = List(D). D = "d". List(S) ~ "(" {S} ")". or although it is longer: A = "a" List(B). B = "b" List(C). C = "c" List(D). D = "d". List(S) ~ {S} . Question 5: ================================================== UNKNOWN1 = UNKNOWN2 (e.g. Edge) UNKNOWN2 = UNKNOWN1 UNKNOWN3 = V (or VertexName) UNKNOWN4 = V UNKNOWN5 = Flexible | Strict UNKNOWN6 = "/" UNKNOWN7 = "*" UNKNOWN8 = Positive UNKNOWN9 = Negative (may switch 8 and 9) UNKNOWN10 = Triple or: "->" Triple UNKNOWN11 = "->" NOTHING UNKNOWN12 = "{" UNKNOWN13 = "}"