www.vustudents.ning.com

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

CS606 Assignment No 04 Solution & Discussion Due Date:05-02-2013

Question No 1: Marks 20
Consider the following grammar productions. Suppose you have an attribute E.type which can
be set to either INT, BOOL. Assume that the type of an expression is set to INT if an error is
detected and you have a routine msg() similar to printf() that can be used to print error
message.
E → CONST {E.type=??}
| ID {E.type =getType(ID.name);}
| E1 +E2 {E.type=??}
| E1< E2 {E.type=??}
| E1= =E2 {E.type=??}
| (E1) {E.type=??}
You are required to add rules to the attribute grammar to calculate E.type for each grammar
production.

Views: 2272

Attachments:

Replies to This Discussion

ECONST {E.type=??} how can i slove

not a  | E1+E2 should also be BOOLEAN??its INT i think 95% true

E  →  CONST          { E.type=INT}

coz constant can't be boolean..??

ok i will check

ok..if you got idea then kindly remove confusion...

how we will write rule for" ID "..?

no,

E1+E2 is boolean .sir said in lecture..it work on binary operator.takes 2 operands and logically + is OR and * is AND.

so E1+E2 . is Boolean.

i am not getting a point .

after type checking, how we will implement Rules.

any one did it  ?

i am not sure but taking guideline frm handouts it will be like this..

for E------>(E1)

Now its implementation will be like

E1.true=E.true

E1.false=E.false

E1.(id.name)=E.(id.name)

good work salma iqbal.

one more confusion now.

what does this sentence mean.?

Assume that the type of an expression is set to INT if an error is
detected and you have a routine msg() similar to printf() that can be used to print error message.

+,<,== are all BOOLEAN..

and (E1)is only INT..

then how we will print error...while there is no error.

1

2

3

4

5

Latest Activity

Lindamalinskiy liked Mani Siddiqui's blog post اشک
7 hours ago
Lindamalinskiy liked Mani Siddiqui's blog post اشک
7 hours ago
Lindamalinskiy, shahzeel khan, Najwa Yaminah and 3 more joined Virtual University of Pakistan
8 hours ago
Najwa Yaminah replied to irshad kausar's discussion math
11 hours ago
Misha princess is now friends with Muhammad Sohaib Akhtar and Muhammad Umar daraz
14 hours ago
15 hours ago
Izhar Ahmad liked Mani Siddiqui's discussion تو نے دیکھا ہے کبھی
15 hours ago
Fatima khan posted a discussion

17 hours ago