GATE / CS ARCHIVE

SUBJECT COLLECTION

Compiler Design · Other / Mixed Topics

6 questions, newest first

Browse topics
2 marks · MCQ
Report issue

Compiler implementation statements

Other / Mixed Topics

Question 42, GATE 2009: Assess I some programming-language parsers have complexity below Θ(n³); II recursion can be implemented with static storage allocation; III no L-attributed definition can be evaluated bottom-up; IV optimization can occur at source and intermediate-code levels. A I/II; B I/IV; C III/IV; D I/III/IV.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

I is true: LL/LR parsing for suitable grammars runs in linear time, below the general cubic CFL bound. II is false for unrestricted recursion under static allocation of activation records, since simultaneous recursive calls need distinct storage. III is false because S-attributed definitions are also L-attributed and can be evaluated bottom-up. IV is true: optimizations may occur at source and intermediate-code levels. Thus I and IV, B. Tail-recursive/bounded special cases do not justify the unrestricted static-allocation claim.

LL/LR parsers for suitable grammars run in linear time, establishing I without claiming every CFG can be parsed that way. Unbounded recursive activation records cannot all be assigned one fixed static location, so II is false in the intended general model. S-attributed definitions are a subclass of L-attributed ones and can be evaluated bottom-up, disproving III’s universal negative. Algebraic source rewrites and intermediate-code optimizations illustrate IV. Therefore I and IV are true.

Original paper, page 9

2 marks · MCQ
Report issue

Nested recursion yielding91

Other / Mixed Topics

Question 2.12, GATE 1998: F(x)=x−10 for x>100, otherwise F(F(x+11)). Evaluate F(95) among 89, 90, 91, 92.
Question 2.12, GATE 1998: F(x)=x−10 for x>100, otherwise F(F(x+11)). Evaluate F(95) among 89, 90, 91, 92.
Tap to enlarge
Your answer
Answer & solution

Answer: C: 91 (no official key was published)

Step through it (21 steps)

First F(100)=F(F(111))=F(101)=91. For x from 95 through 99, x+11 exceeds 100, so F(x+11)=x+1. Hence F(x)=F(x+1) for these five inputs. Chaining gives F(95)=F(96)=…=F(100)=91. Thus C. This local calculation proves the requested value without assuming the more general McCarthy 91 theorem for every input.

Original paper, page 4

2 marks · MCQ
Not in GATE 2027 syllabusReport issue

String head and tail operations

Other / Mixed Topics

Question 2.9, GATE 1995: For s=acbc, head returns the first character, tail removes it, and concat joins strings. Evaluate concat(head(s),head(tail(tail(s)))).
Tap to enlarge
Your answer
Answer & solution

Answer: C: ab (no official key was published)

Starting with s=acbc, the first tail is cbc and the second is bc. The head of that second tail is b. Separately head(s)=a. Concatenating a and b gives ab. This follows the nesting from the inside outward; taking only one tail would produce c instead. Among ac,bc,ab,cc, this is option C.

Original paper, page 4

Not in GATE 2027 syllabusReport issue

Why unrestricted goto is discouraged

Other / Mixed Topics

Question 1.5, GATE 1994: Is unrestricted goto harmful because verification is harder, runtime rises, memory rises, or generated code is necessarily longer?
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Arbitrary jumps can create tangled control flow with many entry points and difficult-to-track invariants. This makes local reasoning about a block’s preconditions and postconditions harder, so program verification and maintenance suffer. A jump itself need not increase runtime, data storage or machine-code length; those effects depend on the program and compiler. The objection is therefore structural reasoning, not a universal performance penalty. Structured conditionals and loops make control-flow boundaries more explicit.

Original paper, page 1

2 marks · MSQ
Report issue

Addition-subtraction swap

Other / Mixed Topics

Question 7.4, GATE 1993: What do a:=a+b; b:=a−b; a:=a−b accomplish for initialized integer variables?
Tap to enlarge
Select all that apply
Answer & solution

Answer: A: exchange a and b, assuming no overflow (no official key was published)

Let the initial values be a0,b0. After the first statement a=a0+b0. The second computes b=(a0+b0)−b0=a0. The final statement gives a=(a0+b0)−a0=b0, completing the swap without a separate temporary. This derivation assumes the intermediate sum is representable or a defined modular arithmetic model. The snippet declares variables but does not initialize them; as a standalone program it would not define starting values. Its intended transformation concerns values supplied before this segment.

Original paper, page 7

2 marks · MSQ
Not in GATE 2027 syllabusReport issue

Compiler and language claims

Other / Mixed Topics

Question 3(x), GATE 1991: Assess A recursive descent cannot handle left recursion; B postfix is best for optimization; C without recursion/pointers dynamic allocation is unnecessary; D C can simulate call-by-name; E no Pascal feature violates strong typing.
Question 3(x), GATE 1991: Assess A recursive descent cannot handle left recursion; B postfix is best for optimization; C without recursion/pointers dynamic allocation is unnecessary; D C can simulate call-by-name; E no Pascal feature violates strong typing.
Tap to enlarge
Select all that apply
Answer & solution

Answer: A, D in the conventional parser model; C requires extra language restrictions (no official key was published)

Naive recursive descent expands a left-recursive nonterminal before consuming input and recurses indefinitely, so A is true for that standard algorithm; specialized modern techniques are outside this model. Optimization usually needs explicit dataflow such as three-address code or DAGs, not merely postfix order, so B is false. C is not guaranteed: runtime-sized arrays can require dynamic storage even without pointers or recursive calls. D is achievable with thunks, using a function plus captured environment to reevaluate an argument; writable parameters additionally need an lvalue-access mechanism. Historical Pascal variant records can bypass type discipline, refuting E. C is sometimes intended under a restricted static-allocation language model, but that restriction is not stated.

Original paper, page 4