• edited by
12,042 views
23 23 votes

Consider the syntax directed translation scheme $\textsf{(SDTS)}$ given in the following. Assume attribute evaluation with bottom-up parsing, i.e., attributes are evaluated immediately after a reduction.

  • $E\rightarrow  E_{1} * T \qquad \{E.val = E_{1}.val * T.val\}$
  • $E\rightarrow  T \qquad \qquad \{E.val = T.val\}$
  • $T\rightarrow  F - T_{1}\qquad \{T.val = F.val - T_{1}.val\}$
  • $T\rightarrow F \qquad \qquad \{T.val = F.val\}$
  • $F\rightarrow 2 \qquad \qquad \{F.val = 2\}$
  • $F\rightarrow 4 \qquad \qquad \{F.val = 4\}$
  1. Using this $\textsf{SDTS},$ construct a parse tree for the expression $4 - 2 - 4 * 2$  and also compute its $E.val$.
  2. It is required to compute the total number of reductions performed to parse a given input. Using synthesized attributes only, modify the $\textsf{SDTS}$ given, without changing the grammar, to find $E.red$, the number of reductions performed while reducing an input to $E$.

3 Answers

Best answer
35 35 votes

   Given expression $4-2-4*2$

Total reductions = 10

  1. Expression value, $E.val = 12$
  2. Total number of reductions performed, $E.red = 10$ (number of non-leaf nodes in the parse tree)

Part B Explanation: https://gateoverflow.in/690/gate-cse-2000-question-19?show=136436#a136436 

• edited by
1 flag:
✌ Low quality (Amitesh Patra “Incomplete, lacks part b. of the question”)
48 48 votes
SDTS to find the number of reductions::

E→ E1 * T {E.red = E1.red+ T.red+1}

E→T {E.red = T.red+1}

T→F - T1 {T.red = F.red + T1.red+1}

T→F {T.red = F.red+1}

F→2 {F.red = 1}

F→4 {F.red = 1}
11 11 votes

A. Given Expression is 4 - 2 - 4 * 2 , which can be rewritten as ((4 - (2 - 4))* 2) which is equal to 12.

Position:
Show:

Related questions

51 51 votes
8 answers 8 answers
18.0k
18.0k views
Kathleen asked Sep 14, 2014
17,960 views
A multiset is an unordered collection of elements where elements may repeat any number of times. The size of a multiset is the number of elements in it, counting repetiti...
31 31 votes
7 answers 7 answers
12.1k
12.1k views
Kathleen asked Sep 14, 2014
12,074 views
Which of the following derivations does a top-down parser use while parsing an input string? The input is scanned from left to right.Leftmost derivationLeftmost derivatio...
41 41 votes
9 answers 9 answers
17.0k
17.0k views
Kathleen asked Sep 14, 2014
17,023 views
Given the following expression grammar:$$\begin{align}E &\to E * F \mid F + E \mid F \\[1em]F &\to F - F \mid id\end{align}$$Which of the following is true?$*$ has higher...
14 14 votes
2 2 answers
4.4k
4.4k views
Kathleen asked Sep 14, 2014
4,444 views
Consider a bank database with only one relation transaction (transno, acctno, date, amount)The amount attribute value is positive for deposits and negative for withdrawa...