GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Backpatching with no fall-through optimisation, numbering from 100, for: if (!(p < q)) x = 1; while (i < n) { if (a < b || c < d) k = k + 1; else k = k - 1; } How many instructions are generated?
- A. 12
- B. 14
- C. 15
- D. 13
Correct answer: D. 13
if with a negated test: 2 jumps + assignment = 3; while test 2 + if-else (4 + 1 + 1 + 1 = 7) + closing goto 1 = 10: total 13.
More Compiler Design questions
- An LR parser for E → id | E [ E ] | ( E ) parses "( id ) [ id ]". Each shift and each reduce is one move (the final accept is not a move)…
- SDD: S → ( S S ) | a. Inherited attribute S.d: the root has S.d = 0 and each child of a node gets parent.d + 1. Synthesised S.v: for a →…
- A Pascal-like scanner uses longest match (ties to the earlier rule) with rules: FLOAT = [0-9]+.[0-9]; INT = [0-9]+; RANGE = ..; DOT =…
- SDD: S → ( S S ) | a. S.d is inherited: root d = 0, children get parent.d + 1. For a → a: S.v = S.d if S.d is even, otherwise −S.d. For S…
- int i = 1; int A[1..4] = {4, 7, 2, 9}; void swap(x, y) { int t = x; x = y; y = t; } The call swap(i, A[i]) is made. The parameters are…
- For S′ → S; S → A | x b; A → a A b | B; B → x, what is the LALR(1) lookahead set of the item B → x · in the state reached from the start…