The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+10 votes
768 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.1k points)
edited by | 768 views

1 Answer

+8 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 (433 points)
edited by
0
What is L.in?

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

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
49,845 questions
54,783 answers
189,421 comments
80,415 users