The Gateway to Computer Science Excellence
+10 votes
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$
in Compiler Design by Veteran (52.2k points)
edited by | 862 views

1 Answer

+9 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}$$
by (443 points)
edited by
+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?

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.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,647 questions
56,458 answers
195,366 comments
100,249 users