hw7soln - inherited idlist.type := type.spectype vardcl ::=...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 415 Spring 2007 HW#5 Solution 1. (i) Problem 4.3.1 Using the the following grammar and actions show what the input a - (b + c) produces. E0 -> E1 + T { E0.nptr := mknode(+, E1.nptr, T.nptr) } E0 -> E1 - T { E0.nptr := mkdone(-, E1.nptr, T.nptr) } E -> T { E.nptr := T.nptr } T -> ( E ) { T.nptr := E.nptr } T -> id { T.nptr := mkleaf(id, id.entry) } - id a + id b id c left right left right
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2. stype.spectype := DOUBLE synthesized stype ::= double synthesized stype.spectype := REAL stype ::= real stype.spectype := INTEGER stype ::= integer synthesized synthesized type ::= stype type.spectype := stype.spectype type ::= array [ICONST1 . . ICONST2] of stype type.spec := array(stype.spec, ICONST1, ICONST2) synthesized inherited idlist ::= ID ID.type = idlist.type idlist0 ::= idlist1, ID inherited inherited idlist1.type := idlist0.type ID.type := idlist0.type
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: inherited idlist.type := type.spectype vardcl ::= idlist : type Problem 2. (ii) Decorated tree for A, B, C : real. Red lines are inherited. Blues line are synthesized. vardcl idlist type: REAL type spectype: REAL : stype spectype: REAL real idlist type: REAL ID type: REAL , ID type: REAL , idlist type: REAL ID type: REAL Problem 2. (iii) The solution neither S-attributed nor L-attributed. S-attributed grammars have no inherited attributes at all. The solution has inherited attributes. L-attributed grammars have left-to-right dataow. The solution has right-to-left dataow. Notice if the top level production rule was vardcl::= type : idlist then the dataow would be left to right, and could be implemented using a L-attributed grammar....
View Full Document

This note was uploaded on 10/29/2010 for the course CS 198:415 taught by Professor Kremer,u. during the Spring '10 term at Rutgers.

Page1 / 3

hw7soln - inherited idlist.type := type.spectype vardcl ::=...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online