Q3. Consider following the attribute grammar for simple declaration. [15]
Your task is to define semantic rules for calculating the values of the attributes.
Grammar:
<dlist> → <tspec> ID <rest>
<tspec> → int
<tspec> → float
<tspec> → char
<rest> → ε
<rest> → , ID <rest>
Terminal symbols:
“ int float char ε ID , “
Nonterminal symbols:
<dlist> <tspec> <rest>
Start symbol:
<dlist>
first we will have to add attributes for sematics rules. int.type = integer //integer float.type = real // real number. char.type = character // 1 byte chracter. Here is list of semantic rules assosiated with each production. <dlist> -> <tspec> ID <rest> (i) <dlist>.type = <tspec>.type (ii) ID.type = <dlist>.type (iii) <rest>.type = <dlist>.type <tspec> -> int (i) <tspec>.type = int.type <tspec> -> float (i) <tspec>.type = float.type <tspec> -> char (i) <tspec>.type = char.type <rest> -> ε ..no rules <rest> -> , ID <rest> (i) <rest>[2].type = <rest>[1].type (ii) ID.type = <rest>[1].type
About Cramster | Terms of Use | Privacy Policy | Contact Us | Press Room | Site Map | Support | Anti-Cheating Policy