Topics in Syntax Directed Translation

Filter by year

Syntax Directed Translation questions

Q65

GATE CS 2022 CSSyntax Directed TranslationNAT2 marks
Consider the following grammar along with translation rules.

S→S1#T{Sval=S1val∗Tval}S \to S_1 \# T \quad \{S_{\text{val}} = S_{1\text{val}} * T_{\text{val}}\}
S→T{Sval=Tval}S \to T \quad \{S_{\text{val}} = T_{\text{val}}\}
T→T1%R{Tval=T1val÷Rval}T \to T_1 \% R \quad \{T_{\text{val}} = T_{1\text{val}} \div R_{\text{val}}\}
T→R{Tval=Rval}T \to R \quad \{T_{\text{val}} = R_{\text{val}}\}
R→id{Rval=idval}R \to \text{id} \quad \{R_{\text{val}} = \text{id}_{\text{val}}\}

Here # and % are operators and id\text{id} is a token that represents an integer and idval\text{id}_{\text{val}} represents the corresponding integer value. The set of non-terminals is {S,T,R,P}\{S, T, R, P\} and a subscripted non-terminal indicates an instance of the non-terminal.

Using this translation scheme, the computed value of SvalS_{\text{val}} for root of the parse tree for the expression 20#10%5#8%2%220\#10\%5\#8\%2\%2 is _____________.
Show answer without attempting

Answer: 80

0/10 correct0 marks

Related topics in Compiler Design