Question

Each numbered item has approximately the same weight. There are a few extra points built into the scoring system. Partial cre
Item 1 uses the following attribute grammar type checking. <A> → ident = <E> (SEMANTIC RULE: <E> .permittedTypes (typeLookUp(
(SEMANTIC RULE: int - (<E>[2].actua!Type ← ǐf <E> . actual Type AND <E>[3].actualTypeint) else if (<E>[2].actualType E int,lo
Each numbered item has approximately the same weight. There are a few extra points built into the scoring system. Partial credit is available. Show all work! Answers without adequate support will not receive full credit 1. Consider the attribute grammar for type checking of assignment statements given in the Supplement Sketch the parse tree for the following assignment statement. a#b*(c + d) Suppose that type Lookup("a")-float, typeLookup("b") int, typeLookup("c")-int, and a. float. Decorate the parse tree with correct attribute values typeLookup("d") According to the attribute grammar, is this assignment type correct? Explain why or why b. not
Item 1 uses the following attribute grammar type checking. → ident = (SEMANTIC RULE: .permittedTypes (typeLookUp(ident. Iexeme) ← if -int) then (int) then tint,long) then (int,float) then (int,long, float,double) olse if (typeLookup (ident.lexeme) long) else if (typeLookUp (ident.lexeme) float) else if (typeLookUp(ident. lexeme) -= double) PREDICATE .actualTypo .permittedTypes ( SEMANTIC RULE: ← ([2].actualType int .actualType if -- AND [3).actualTypeint) then int else if KE [2).actualType e (int,long) and [3].actualType E (int,long) then long else if E 12].actualType e int,float) and [3].actualType e int,float) then float else double ) Continued on next page
(SEMANTIC RULE: int - ([2].actua!Type ← ǐf . actual Type AND [3].actualTypeint) else if ([2].actualType E int,long) else if (([2].actualType e fint,float) then int and [3].actualType e (int,long then long and [3].actualType e (int,float) then float else double ) (SEMANTIC RULE : . actualType ← [2]. actualType → ident {SEMANTIC RULE : . actualType ← typeLookup (ident, lexeme) }
0 0
Add a comment Improve this question Transcribed image text
Answer #1

a)a. ERt

b)

The assignment is type correct.

Traversing the parse tree would lead to the following reductions:

Reduction <E>.actualType
E->ident(b) int
E->ident(c) int
E->ident(d) float
E->E+E int and float = float
E->(E) float
E->E*E int * float = float
A->ident = E float

In the last production A->ident(a) = E, since typeLookUp(a) = float, so <E>.permitableTypes appears to be {int,float}, and on traversing the parse tree by the above reductions, the type of <E> also comes out to be float, hence the assignment is type correct.

Add a comment
Know the answer?
Add Answer to:
Each numbered item has approximately the same weight. There are a few extra points built into the scoring system. Partial credit is available. Show all work! Answers without adequate support wi...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT