862 views

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$

edited | 862 views

$$\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}$$
by (443 points)
edited
+1
What is L.in?

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

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

+1
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.