retagged by
3,052 views
15 votes
15 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$
retagged by

1 Answer

Best answer
18 votes
18 votes
$$\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}$$

Related questions

7 votes
7 votes
1 answer
2