GATE Computer ScienceHardGATE CS (PYQ pattern)
A compiler generates jumping code by backpatching (each relation gives 'if r goto _' then 'goto _', numbering from 100) for: if (!(a < b) && (c < d || e < f)) x = 1; else x = 2; In the generated code, to which instruction number does the false-branch 'goto' of the test a < b (number 101) jump?
- A. 100
- B. 104
- C. 102
- D. 103
Correct answer: C. 102
'!' swaps the lists, so the 'goto' after a<b (101) is now the true exit of !(a<b) and is backpatched to the start of the (c<d || e<f) test, i.e. 102; the 'if a<b goto' at 100 becomes a false exit and goes to the else part.
More Compiler Design questions
- Compute FIRST of every non-terminal of S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε, treating ε as a member of FIRST when the…
- For S → A b B | c; A → a | ε; B → c B | ε (augmented), in how many LR(0) states is there a conflict, and how many reduce entries does the…
- For S → A B | B C; A → a A | ε; B → b B | ε; C → c C | d, which statement is FALSE?
- In S → A B; A → a | ε; B → A b | c, FOLLOW(A) does not contain . Which of these productions, each added to the grammar on its own, put…
- For S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε (augmented), in how many states is there a conflict in the SLR(1) table, and in how…
- In 1: i = 0; 2: c = 2; 3: L1: if i >= n goto L3; 4: d = c 3; 5: if i > k goto L2; 6: c = 2; 7: L2: e = d + 1; 8: f = a b; 9: i = i + 1…