1,790 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$

### 1 comment

Similar question: GATE2019-36

$$\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}$$

What is L.in?

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

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

$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.

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.

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