retagged by
5,693 views
19 19 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$

2 Answers

Best answer
23 23 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}$$
edited by
Position:
Show:

Related questions

75 75 votes
9 answers 9 answers
39.5k
39.5k views
Kathleen asked Sep 13, 2014
39,508 views
The access times of the main memory and the Cache memory, in a computer system, are $500$ n sec and $50$ nsec, respectively. It is estimated that $80\%$ of the main memor...
29 29 votes
4 answers 4 answers
4.5k
4.5k views
go_editor asked Apr 24, 2016
4,488 views
Write $3$ address intermediate code (quadruples) for the following boolean expression in the sequence as it would be generated by a compiler. Partial evaluation of boolea...
11 11 votes
1 answers 1 answer
3.8k
3.8k views
Kathleen asked Sep 13, 2014
3,753 views
Write short answers to the following:Which of the following macros can put a macro assembler into an infinite loop?.MACRO M1,X .IF EQ,X M1 X+1 .ENDC .IF NE,X .WORD X .END...
56 56 votes
2 answers 2 answers
21.8k
21.8k views
Kathleen asked Sep 13, 2014
21,761 views
Consider the $\text{SLR(1)}$ and $\text{LALR (1)}$ parsing tables for a context free grammar. Which of the following statement is/are true?The goto part of both tables m...