The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+10 votes
490 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$
asked in Compiler Design by Veteran (59.4k points)
edited by | 490 views

2 Answers

+7 votes
Best answer
PRODUCTION RULE                                                        SEMANTIC ACTIONS

$D \rightarrow TL$                                                                          $L.in:=T.type$

$T  \rightarrow int$                                                                           $T.type:=integer$

$T \rightarrow  real$                                                                        $T.type:=real$

$L \rightarrow L,id$                                                                      $L1.in=L.in$

                                                                                       Enter_type$(id.entry, L.in)$

$L  \rightarrow  id$                                                                        Enter_type$(id.entry, L.in)$
answered by (423 points)
selected by
0
What is L.in?

Why two times Enter_Type(id.entry, L.in)?
+3 votes
quadruples consists of the 4-section they are operator, operand1, operand2, result

operator                 operand1           operand2                    result

+                               a                     b                              t1

+                               c                      d                             t2

>                               t1                     t2                            t3

>                                a                     c                             t4

<                               b                      d                             t5

and                            t4                    t5                             t6

or                              t3                     t6                            t7
answered by (423 points)


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

34,770 questions
41,730 answers
118,876 comments
41,381 users