in Compiler Design retagged by
1,790 views
12 votes

Write syntax directed definitions (semantic rules) for the following grammar to add the type of each identifier to its entry in the symbol table during semantic analysis. Rewriting the grammar is not permitted and semantic rules are to be added to the ends of productions only.

  • $D \rightarrow TL;$
  • $T \rightarrow \text{int}$
  • $T \rightarrow \text{real}$
  • $L \rightarrow L,id$
  • $L \rightarrow id$
in Compiler Design retagged by
1.8k views

1 comment

Similar question: GATE2019-36

0

1 Answer

15 votes
 
Best answer
$$\begin{array}{|l|l|} \hline \textbf{PRODUCTION RULE} & \textbf{SEMANTIC ACTIONS} \\\hline  D \rightarrow TL  & L.in:=T.type  \\\hline  T  \rightarrow int & T.type:=integer \\\hline T \rightarrow  real & T.type:=real \\\hline  L \rightarrow L,id & L1.in=L.in \\&Enter\_type(id.entry, L.in)  \\\hline L  \rightarrow  id & Enter\_type(id.entry, L.in)  \\\hline \end{array}$$
edited by

7 Comments

What is L.in?

Why two times Enter_Type(id.entry, L.in)?
1
3

@mehul vaidya  The provided link isn't active anymore. Can you please provide the new link for this?

0

$L.in$ is an inherited attribute. Its value can be passed from left sibling to right sibling via the root of the subtrees, or from one node to its child.

This is a variant of a grammar from the dragon book that gives you sentences of the form $int\ x,y,z$, from chapter 5 on SDDs/SDTs. It is L-attributed, because it has inherited attributes.

0

When we are going to perform this action "Enter_type(id.entry, L.in" for the production L$\rightarrow$ L, id?

I mean while inheriting the "in" from Parent or while we perform the reduction.

0
Same question (as it is grammar) asked in GATE 2019.
0

Related questions