286 views
1 1 vote

Consider the following Syntax Directed Translation (SDT) scheme where $S$ is the start symbol and $id.\mathrm{val}$ represents the numerical value of an identifier:

$$
\begin{gathered}
S \rightarrow E \quad\{\text { print }(E . \text { val })\} \\
E \rightarrow E_1+T \quad\left\{E . \text { val }=E_1 . \text { val }+T . \text { val }\right\} \\
E \rightarrow T \quad\{E . \text { val }=T . \text { val }\} \\
T \rightarrow T_1 * F \quad\left\{T . \text { val }=T_1 . \text { val } \times \text { F.val }\right\} \\
T \rightarrow F \quad\{T . \text { val }=F . \text { val }\} \\
F \rightarrow(E) \quad\{\text { F.val }=\text { E.val }\} \\
F \rightarrow i d \quad\{\text { F.val }=i d . \text { val }\}
\end{gathered}
$$


Which of the following statement(s) is/are TRUE regarding this SDT?

  1. THE UNDERLYING GRAMMAR IS AMBIGUOUS.
     
  2. THE ATTRIBUTES IN THIS SDD ARE ENTIRELY SYNTHESIZED.
     
  3. THE SDT CAN BE EVALUATED DURING BOTTOM-UP PARSING WITHOUT ANY MODIFICATIONS.
     
  4. FOR THE INPUT $3 + 4 * 5$, THE PRINTED VALUE WILL BE 35 IF THE OPERATORS ARE TREATED AS LEFT-ASSOCIATIVE.

2 Answers

0 0 votes
The grammar is the standard expression grammar which is unambiguous (A is false). All values flow upward from children to parents, making them synthesized (B is true). Since all actions are at the ends of productions, it is an S-attributed definition, which can be easily handled by a bottom-up parser (C is true). For D, the value would be $23$ (standard precedence), not $35$.
0 0 votes
option A is wrong
reason: every production is unambigueous and only 1 parse trees exit for every grammar
option B is correct
reason: every attribute is systhesized
option C is correct
reasons: Since it is S-attributed so it data flows from chlid to parent so it parsed using bottom up parsing
option D  is wrong
reasons: 3+4*5 = 23
Answer:
Position:
Show:

Related questions

2 2 votes
3 3 answers
520
520 views
GO Classes asked Feb 4
520 views
A lexical analyzer is designed for a new language with the following rules for token generation:$\mathrm{KEYWORD1}: \verb|if|$ $\mathrm{KEYWORD2}: \verb|iff|$ $\mathrm{ID...
2 2 votes
5 5 answers
528
528 views
GO Classes asked Feb 4
528 views
Consider the following arammar $G$ :$$\begin{aligned}& S \rightarrow(L) \mid a \\& L \rightarrow L, S \mid S\end{aligned}$$Which of the following statement(s) is/are TRUE...
5 5 votes
2 2 answers
293
293 views
GO Classes asked Feb 4
293 views
Consider a Bottom-Up parser for a grammar $G$. During the parsing of an input string $w$, the parser reaches a configuration where the stack contains the prefix $\alpha$ ...
2 2 votes
2 2 answers
298
298 views
GO Classes asked Feb 4
298 views
Which of the following statement(s) is/are TRUE regarding Lexical Analysis and Regular Expressions?The number of states in a minimal Deterministic Finite Automaton (DFA) ...