{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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
Image of page 1

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

View Full Document Right 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
Image of page 2
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 dataflow. The solution has right-to-left dataflow. Notice if the top level production rule was vardcl::= type : idlist then the dataflow would be left to right, and could be implemented using a L-attributed grammar....
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern