GATEverse
← GATE CSE 2022

Q55

NAT2 marks

Consider the following grammar along with translation rules.

S→S1#T{S.val=S1.val  ∗T.val}S→T{S.val=T.val}T→T1%R{T.val=T1.val÷R.val}T→R{T.val=R.val}R→id{R.val=id.val}\begin{aligned} & S \rightarrow S_{1} \# T \qquad \{S._{\text{val}} =S_{1}. _{\text{val}} \; ^{\ast} T._{\text{val}}\}\\ & S \rightarrow T \qquad \qquad \{S._{\text{val}} = T._{\text{val}}\}\\ & T \rightarrow T_{1} \% R \qquad \{T._{\text{val}} =T_{1}._{\text{val}} ÷ R._{\text{val}}\}\\ & T \rightarrow R \qquad \qquad \{T._{\text{val}} = R._{\text{val}}\} \\ & R \rightarrow \text{id} \qquad \qquad \{R._{\text{val}} = \text{id}._{\text{val}}\} \end{aligned}

Here #\# and %\% are operators and id\text{id} is a token that represents an integer and id.val\text{id}._{\text{val}} represents the corresponding integer value. The set of non-terminals is {S, T, R, P}\{\text{S, T, R, P}\} and a subscripted non-terminal indicates an instance of the non-terminal. Using this translation scheme, the computed value of S.valS._{\text{val}} for root of the parse tree for the expression 20#10%5#8%2%220 \# 10 \% 5 \# 8 \% 2 \% 2 is ________________.

Sign in to save attempts.

Loading…