• edited by
14,789 views
22 22 votes

​Consider the following expression: $x[i]=(p+r) *-s[i]+u / w$. The following sequence shows the list of triples representing the given expression, with entries missing for triples $(1), (3)$, and $(6)$.

$$\begin{array}{|c|c|c|c|}
\hline(0) & + & p & r \\
\hline(1) & & & \\
\hline(2) & \text{uminus} & (1) & \\
\hline(3) & & & \\
\hline(4) & / & u & w \\
\hline(5) & + & (3) & (4) \\
\hline(6) & & & \\
\hline(7) & = & (6) & (5) \\
\hline
\end{array}$$
Which one of the following options fills in the missing entries CORRECTLY?

  1. $(1)$ $\text{=}$$\text{[ ] s } i \quad(3)$ $\text{*}$ $(0)(2) $ $\quad(6) $$\text{[ ]=}$ $\textit{x }i$
  2. $(1)$ $\text{[ ]}$$=\text{s } i \quad(3)-(0)(2) \quad(6) =$$\text{[ ]}$ $\textit{x }(5)$
  3. $(1)$ $\text{=}$$\text{[ ] s } i \quad(3)$ $\text{*}$ $(0)(2) $ $\quad(6) $$\text{[ ]=}$ $\textit{x }(5)$
  4. $(1)$ $\text{[ ]}$$=\text{s } i \quad(3)-(0)(2) \quad(6) =$$\text{[ ]}$ $\textit{x }i$

5 Answers

26 26 votes

We can do this question as option elimination also as @Cxdr suggested on comments.

But, let's actually try to build this table.
Given expression is:  x[i] =  (p+r)*-s[i]+u/w.
converting x[i] and s[i] is little overwhelming, so try to think like this

since, we are using value of s[i], let's write it in this way,
t1 = s[i] ( we have two operands apart from temporary variable and two operator)
in triple symbol table it could be written as,
=[]  s  i  

also, we are putting computed value in x[i], let's write it in this way
x[i] = t1 
In symbol table it could be written as, 
[]=  x  i ( we have two operands apart from temporary variable and two operator)

Now, everything is easy anyways, let's build the table
 

(0)+pr
(1)=[]si
(2)uminus(1) 
(3)*(0)(2)
(4)/uw
(5)+(3)(4)
(6)[]=xi
(7)=(6)(5)


 

4 4 votes
A is the correct answer.

Expalnation: Going from left to right we resolve the brackets first. (p+r) is already given, now we solve s[i]. then comes unary minus as per operator preference. Then we solve * which acts between 0 & 2 (B & D eliminated) and / , + subsequently. Then x[i] address is calculated(step 6) where the final result (obtained in step 5) is stored in the last step (7). The assignment operator has lowest preference so it is done at last.
• edited by
4 4 votes
  • To solve these types of questions, analytical skills are key. From the given expression and table we can see following two 

    • (0) : p + r
    • (4) : u / w
  • I derived these expressions simply by analyzing the given expression. From this, we can conclude:

    • (5) : (3) + (4) and (7) : (6) = (5)
  • Therefore:

    • (5) = (3) + (4), where (4) is fixed as u/v.
    • This implies (3) must be (p + r) * -s[i].
  • Additionally:

    • (2) is -(1) because "-" here is unary.
  • Consequently:

    • (3) must be *(0)(2), as the unary "-" is already associated with (2).
  • With this information:

    • Options B and D are eliminated.
  • Therefore:

    • (1) must be s[i].
    • The same logic applied to s[i] should also be applied to x[i].
    • This also eliminates option D.
  • Conclusion: Option A is correct

Answer:
Position:
Show:

Related questions

19 19 votes
2 2 answers
11.2k
11.2k views
Arjun asked Feb 16, 2024
11,214 views
Consider the following context-free grammar where the start symbol is $\text{S}$ and the set of terminals is $\{a, b, c, d\}$.$$\begin{array}{l}S \rightarrow A a A b \mid...
31 31 votes
9 9 answers
13.3k
13.3k views
Arjun asked Feb 16, 2024
13,347 views
​​​​Consider a context-free grammar $\text{G}$ with the following $3$ rules.$$S \rightarrow a S, S \rightarrow a S b S , S \rightarrow c$$ Let $w \in L(G)$. Let $...
21 21 votes
3 3 answers
13.9k
13.9k views
Arjun asked Feb 16, 2024
13,911 views
Consider the following augmented grammar, which is to be parsed with a $\text{SLR}$ parser. The set of terminals is $\{a, b, c, d, \#, @\}$\[\begin{array}{l}S^{\prime} \r...
22 22 votes
6 6 answers
12.1k
12.1k views
Arjun asked Feb 16, 2024
12,142 views
​​​Consider the following two sets:$$\begin{array}{|ll|ll|}\hline & \textbf{Set X} & & \textbf{Set Y} \\\hline \text{ P.} & \text{Lexical Analyzer } & \text{1.}& \text...