Intermediate Code Generation(Compiler Design) MCQs
Intermediate Code Generation” from Compiler Design for the GATE exam
1.
Which of the following is not a form of intermediate code representation?
A) Three-address code
B) Syntax tree
C) Parse tree
D) Assembly code
✅ Answer: D) Assembly code
Solution:
Assembly code is machine-dependent, while the other three are machine-independent intermediate representations (IRs) used before code generation.
2.
Which one of the following is a valid three-address statement?
A) x = y + z * 2
B) x = y + z + w
C) x = y + z; w = x * 3
D) x = y + (z * w)
✅ Answer: A) x = y + z * 2
Solution:
A single three-address instruction contains at most one operator on the right side. Option (A) can be broken into:t1 = z * 2; x = y + t1.
3.
Intermediate code is mainly generated to:
A) Optimize parsing speed
B) Provide machine independence
C) Increase code size
D) Reduce semantic errors
✅ Answer: B) Provide machine independence
Solution:
IR acts as a bridge between front end and back end, allowing portability across architectures.
4.
Which of the following correctly represents a quadruple format?
A) (operator, operand1, operand2, result)
B) (operand1, operand2, operator, result)
C) (operator, result, operand1, operand2)
D) (result, operator, operand1, operand2)
✅ Answer: A) (operator, operand1, operand2, result)
Solution:
In quadruples, operator precedes operands; the result field stores the location where output is kept.
5.
In triples, how are intermediate results represented?
A) Using temporary variable names
B) Using numeric position labels
C) Using symbol table indices
D) Using direct registers
✅ Answer: B) Using numeric position labels
Solution:
Triples replace temporary variables with statement numbers, saving storage but complicating code movement.
6.
Given expression: x = (a + b) * (c - d), how many three-address statements are required?
A) 1
B) 2
C) 3
D) 4
✅ Answer: C) 3
Solution:t1 = a + bt2 = c - dx = t1 * t2
→ 3 instructions.
7.
In quadruple representation, if statement 3 is (*, T1, T2, T3), then it means:
A) T3 = T1 * T2
B) T1 = T2 * T3
C) T2 = T1 * T3
D) T1 = T3 * T2
✅ Answer: A) T3 = T1 * T2
Solution:
The order in quadruples is (operator, operand1, operand2, result).
8.
Which of the following is most suitable for implementing optimization techniques?
A) Target code
B) Intermediate code
C) Assembly code
D) Source code
✅ Answer: B) Intermediate code
Solution:
Most optimizations are easier and machine-independent at the IR level before final code generation.
9.
The Directed Acyclic Graph (DAG) representation of expressions helps in:
A) Parsing
B) Code generation only
C) Common subexpression elimination
D) Constant folding only
✅ Answer: C) Common subexpression elimination
Solution:
DAG merges identical subexpressions, avoiding redundant computation.
10.
Three-address code instruction goto L1 if x < y is equivalent to:
A) Conditional jump
B) Unconditional jump
C) Function call
D) Return statement
✅ Answer: A) Conditional jump
Solution:
This instruction transfers control to label L1 only if the condition x < y is true.
11.
Which of the following is a benefit of generating an intermediate code?
A) Faster compilation
B) Easier debugging
C) Machine independence and optimization
D) Reduced lexical errors
✅ Answer: C) Machine independence and optimization
Solution:
Intermediate representation separates front-end and back-end concerns, improving portability and optimization.
12.
In three-address code, how many operands are used at most in one instruction?
A) 1
B) 2
C) 3
D) 4
✅ Answer: C) 3
Solution:
The name “three-address” means each instruction can have up to three operands (two sources + one destination).
13.
For the expression x = a * b + c * d, how many temporary variables are required in three-address form?
A) 1
B) 2
C) 3
D) 4
✅ Answer: B) 2
Solution:t1 = a * bt2 = c * dx = t1 + t2
→ two temporaries.
14.
A quadruple and triple differ mainly in:
A) Type of operations supported
B) Number of operands
C) Way intermediate results are represented
D) Control flow
✅ Answer: C) Way intermediate results are represented
Solution:
Triples use statement numbers; quadruples use explicit temporary variables.
15.
If the expression is p = q + r * s, what is the first operator executed?
A) +
B) *
C) =
D) Depends on compiler
✅ Answer: B) *
Solution:
Operator precedence ensures multiplication before addition.
16.
A syntax-directed translation scheme that generates three-address code during parsing belongs to:
A) Semantic analysis
B) Intermediate code generation
C) Code optimization
D) Syntax analysis
✅ Answer: B) Intermediate code generation
Solution:
This phase attaches translation actions to grammar rules that produce IR during parsing.
17.
The intermediate code generation phase takes input from:
A) Syntax analyzer
B) Lexical analyzer
C) Semantic analyzer
D) All of these
✅ Answer: D) All of these
Solution:
Intermediate code requires token information (lexical), syntax structure (parser), and semantic validation.
18.
Which of the following does not belong to three-address code forms?
A) x = y + z
B) x = -y
C) x = y
D) x = y + z + w
✅ Answer: D) x = y + z + w
Solution:
Only one operator per instruction; this one requires breaking into multiple statements.
19.
Which IR form explicitly shows computation order?
A) Syntax tree
B) DAG
C) Quadruples
D) Symbol table
✅ Answer: C) Quadruples
Solution:
Quadruples maintain an ordered list of operations for sequential computation.
20.
The label field in intermediate code is used for:
A) Arithmetic operations
B) Control flow
C) Temporary variable naming
D) Symbol table lookup
✅ Answer: B) Control flow
Solution:
Labels denote jump targets in control flow statements like loops and conditionals.
21.
For Boolean expression x && y || z, short-circuit evaluation in intermediate code uses:
A) Backpatching
B) Constant folding
C) Loop unrolling
D) Dead code elimination
✅ Answer: A) Backpatching
Solution:
Backpatching is used to fill jump addresses later during Boolean expression translation.
22.
In quadruple (+, op1, op2, result), which operation occurs first?
A) Assignment
B) Addition
C) Both simultaneously
D) Depends on operator precedence
✅ Answer: B) Addition
Solution:
Operator field represents the arithmetic operation performed before storing result.
23.
Intermediate code generation helps in separating:
A) Syntax and semantics
B) Machine-dependent and machine-independent phases
C) Front end and back end of compiler
D) Both B and C
✅ Answer: D) Both B and C
Solution:
IR forms a bridge between the machine-independent front end and machine-dependent back end.
24.
A DAG node with two parents represents:
A) Common subexpression
B) Redundant variable
C) Constant propagation
D) Unreachable code
✅ Answer: A) Common subexpression
Solution:
When two expressions share the same computation, they point to a single DAG node.
25.
In a DAG representation, leaf nodes represent:
A) Operators
B) Constants or variables
C) Temporary results
D) Control links
✅ Answer: B) Constants or variables
Solution:
Leaves store operands (variables or constants), while internal nodes represent operators.
Intermediate Code Generation – Compiler Design
26.
The intermediate code for if (a < b) x = y + z; else x = y - z; will include how many labels?
A) 1
B) 2
C) 3
D) 4
✅ Answer: C) 3
Solution:
Typically, if-else requires three labels: one for the true branch, one for the false branch, and one for the exit point.
27.
For while (i < 5) i = i + 1;, the three-address code will have how many jump statements?
A) 1
B) 2
C) 3
D) 4
✅ Answer: B) 2
Solution:
One jump to test the condition and another unconditional jump to loop back.
28.
In the intermediate representation of an expression tree, internal nodes represent:
A) Variables
B) Operators
C) Temporary variables
D) Constants
✅ Answer: B) Operators
Solution:
Internal nodes denote operations, while leaves hold operands.
29.
Which statement about quadruples is incorrect?
A) Easy to reorder
B) Difficult to maintain temporary variables
C) Each operation stored explicitly
D) No explicit temporaries used
✅ Answer: D) No explicit temporaries used
Solution:
Quadruples do use explicit temporaries; that’s what differentiates them from triples.
30.
For expression x = a * b + c * d + e, number of three-address instructions = ?
A) 3
B) 4
C) 5
D) 6
✅ Answer: B) 4
Solution:t1 = a * bt2 = c * dt3 = t1 + t2x = t3 + e → 4 statements.
31.
In a triple, intermediate results are identified by:
A) Temporary variables
B) Statement numbers
C) Stack addresses
D) Register names
✅ Answer: B) Statement numbers
Solution:
Each statement can refer to previous computations by their index.
32.
An advantage of indirect triples over triples is:
A) Faster arithmetic
B) Easier code reordering
C) Reduced memory usage
D) Simpler parsing
✅ Answer: B) Easier code reordering
Solution:
Indirect triples maintain a table of pointers, allowing rearrangement of computation order.
33.
Which of the following is not a benefit of intermediate code?
A) Portability
B) Simpler optimization
C) Faster execution
D) Machine independence
✅ Answer: C) Faster execution
Solution:
Intermediate code is slower than final machine code; it’s meant for translation, not execution.
34.
In three-address code, instruction x = *y denotes:
A) Value of y assigned to x
B) Content of memory at y assigned to x
C) Address of y assigned to x
D) Value of x assigned to memory at y
✅ Answer: B) Content of memory at y assigned to x
Solution:
The * operator indicates pointer dereferencing.
35.
For instruction *x = y, the meaning is:
A) Assign y to x
B) Assign y to address pointed by x
C) Assign x to y
D) Load address of y to x
✅ Answer: B) Assign y to address pointed by x
Solution:
The left-hand * means “store in memory at address x”.
36.
Intermediate code generation comes after which compiler phase?
A) Code optimization
B) Syntax analysis
C) Semantic analysis
D) Code generation
✅ Answer: C) Semantic analysis
Solution:
IR is generated once syntax and semantics are validated.
37.
Which of the following intermediate forms is closest to assembly language?
A) Syntax tree
B) Three-address code
C) Quadruple
D) Postfix notation
✅ Answer: B) Three-address code
Solution:
Three-address code resembles low-level assembly with simple operations.
38.
For expression a = b + c * d / e, number of temporaries required = ?
A) 1
B) 2
C) 3
D) 4
✅ Answer: C) 3
Solution:t1 = c * d; t2 = t1 / e; a = b + t2.
39.
In DAG representation, leaf nodes represent:
A) Operators
B) Constants or variables
C) Temporaries only
D) Control instructions
✅ Answer: B) Constants or variables
Solution:
Leaf nodes are operands; inner nodes are operations.
40.
The postfix form of expression (x + y) * (z - w) is:
A) x y + z w - *
B) x y z w + - *
C) x y z w * + -
D) x + y - z * w
✅ Answer: A) x y + z w - *
Solution:
Convert infix to postfix following operator precedence and parentheses.
41.
Which operation is represented by three-address code param a?
A) Parameter passing
B) Return value
C) Function definition
D) Variable initialization
✅ Answer: A) Parameter passing
Solution:param instructions push function arguments on stack before call.
42.
In function calls, the instruction call p, 3 denotes:
A) Call procedure p with 3 arguments
B) Call procedure p at line 3
C) Recursive call
D) Call 3 times
✅ Answer: A) Call procedure p with 3 arguments
Solution:
The number indicates count of parameters passed.
43.
In intermediate code, return x means:
A) End program
B) Return control and value x to caller
C) Go to start of procedure
D) Terminate compiler
✅ Answer: B) Return control and value x to caller
Solution:
Used to end function execution and send value to the calling routine.
44.
Backpatching is used to:
A) Optimize arithmetic expressions
B) Fill in jump addresses
C) Remove redundant labels
D) Translate literals
✅ Answer: B) Fill in jump addresses
Solution:
In control flow translation, jump targets are unknown initially and are later patched.
45.
Which data structure supports backpatching most efficiently?
A) Stack
B) Queue
C) Linked list
D) Symbol table
✅ Answer: C) Linked list
Solution:
Backpatching lists maintain pointers to instructions waiting for target labels.
46.
The IR best suited for machine-dependent optimization is:
A) Three-address code
B) DAG
C) Syntax tree
D) Machine code
✅ Answer: A) Three-address code
Solution:
It’s closer to machine code and allows instruction-level optimization.
47.
In a three-address code, instruction x = y represents:
A) Assignment
B) Comparison
C) Pointer dereference
D) Function call
✅ Answer: A) Assignment
Solution:
Simple data transfer operation assigning value of y to x.
48.
Intermediate code generation simplifies:
A) Lexical analysis
B) Code portability
C) Parsing speed
D) Assembly generation
✅ Answer: B) Code portability
Solution:
IR abstracts machine details, allowing reuse of front end for multiple targets.
49.
What is the intermediate representation of array access a[i] = b + c?
A) t1 = b + c; a[i] = t1
B) a = i + b + c
C) t1 = a + b; i = t1 + c
D) a = b + c[i]
✅ Answer: A) t1 = b + c; a[i] = t1
Solution:
One temp for right-hand side expression, then assignment to array element.
50.
Intermediate code of pointer assignment *p = q + r is:
A) t1 = q + r; *p = t1
B) p = q + r; *t1 = p
C) q = *r + p
D) p = *q + r
✅ Answer: A) t1 = q + r; *p = t1
Solution:
Evaluates arithmetic first, then stores result into location pointed by p.
51.
What does SSA (Static Single Assignment) form ensure?
A) No loops exist
B) Each variable is assigned once
C) All variables are constant
D) Recursion is avoided
✅ Answer: B) Each variable is assigned once
Solution:
SSA simplifies optimization by unique variable assignment.
52.
An intermediate representation should be:
A) Machine-specific
B) Readable only by assembler
C) Easy to translate and optimize
D) Dependent on syntax
✅ Answer: C) Easy to translate and optimize
Solution:
It acts as a bridge allowing efficient translation and optimization.
53.
Three-address code t1 = x < y represents:
A) Conditional expression
B) Assignment
C) Function call
D) Array access
✅ Answer: A) Conditional expression
Solution:
Comparison generates Boolean result for use in later branches.
54.
The intermediate code for if (x <= y) z = 10; can be:
A) if x <= y goto L1; L1: z = 10
B) goto L1 if x <= y; z = 10
C) ifFalse x <= y goto L2; z = 10
D) goto L1; z = 10
✅ Answer: C) ifFalse x <= y goto L2; z = 10
Solution:
The false condition branches to label after assignment.
55.
The postfix for expression a + b * (c + d) is:
A) a b c d + * +
B) a b + c d * +
C) a b c + d * +
D) a b c + d + *
✅ Answer: A) a b c d + * +
Solution:
Parentheses evaluated first, maintaining precedence.
56.
Intermediate code improves compiler retargeting because:
A) It directly executes
B) It abstracts machine details
C) It requires fewer instructions
D) It optimizes parsing
✅ Answer: B) It abstracts machine details
Solution:
Machine independence allows reuse of compiler front-end.
57.
Which of the following best defines “basic block”?
A) Sequence with single entry and single exit
B) Looping structure
C) Group of unrelated statements
D) Data segment
✅ Answer: A) Sequence with single entry and single exit
Solution:
Basic blocks are atomic units for optimization and control flow analysis.
58.
In a three-address code sequence, each instruction:
A) Performs one operation
B) Performs multiple operations
C) Represents full program logic
D) Includes nested conditions
✅ Answer: A) Performs one operation
Solution:
Each TAC represents a simple operation for optimization ease.
59.
Intermediate representation between high-level and assembly code is:
A) Syntax tree
B) Abstract machine code
C) Intermediate code
D) Bytecode
✅ Answer: C) Intermediate code
Solution:
It sits between source-level constructs and target-level instructions.
60.
Which of the following is machine-dependent?
A) Parse tree
B) Intermediate code
C) Target code
D) Syntax tree
✅ Answer: C) Target code
Solution:
Target code depends on processor architecture.
61.
In three-address code, goto L1 means:
A) Conditional branch
B) Unconditional branch
C) Function call
D) Return statement
✅ Answer: B) Unconditional branch
Solution:
Transfers control directly to label L1.
62.
Intermediate code simplifies optimization because:
A) It is high level
B) It is architecture neutral
C) It is machine code
D) It uses registers
✅ Answer: B) It is architecture neutral
Solution:
Machine independence enables general optimization techniques.
63.
An instruction x = -y in three-address code performs:
A) Logical negation
B) Arithmetic negation
C) Address inversion
D) Bitwise complement
✅ Answer: B) Arithmetic negation
Solution:
Unary minus operator negates the numeric value.
64.
In quadruples, the result of one instruction can be used in another by:
A) Copying operand value
B) Using result field reference
C) Recomputing expression
D) Using access links
✅ Answer: B) Using result field reference
Solution:
Result names are used as operands in subsequent instructions.
65.
The number of temporaries for x = a + b + c + d is:
A) 1
B) 2
C) 3
D) 4
✅ Answer: C) 3
Solution:t1 = a + b; t2 = t1 + c; x = t2 + d.
66.
For Boolean if (x && y) z = 1;, how many conditional jumps required?
A) 1
B) 2
C) 3
D) 4
✅ Answer: B) 2
Solution:
One check for x, and another for y if first is true.
67.
Which IR form helps eliminate redundant subexpressions easily?
A) DAG
B) Quadruple
C) Three-address code
D) Postfix
✅ Answer: A) DAG
Solution:
DAG merges identical operations into single nodes.
68.
Three-address code supports maximum of:
A) 2 operands
B) 3 operands
C) 4 operands
D) Unlimited operands
✅ Answer: B) 3
Solution:
Typically two operands and one result field.
69.
Which field is not present in a triple representation?
A) Operator
B) Operand 1
C) Operand 2
D) Result
✅ Answer: D) Result
Solution:
Triples omit result field; results are implicit by position.
70.
A phi (Φ) function in SSA form merges:
A) Loops
B) Control flow
C) Variable values from different paths
D) Constants
✅ Answer: C) Variable values from different paths
Solution:
Φ-function combines multiple assignments into one variable in SSA.
71.
Intermediate code for function call sum(a,b) is:
A) param a; param b; call sum,2
B) sum a b,2
C) call sum(a,b)
D) param 2; call a,b
✅ Answer: A) param a; param b; call sum,2
Solution:
Standard form for procedure call with parameters.
72.
Which is most suitable for register allocation optimization?
A) DAG
B) Quadruple
C) Three-address code
D) Parse tree
✅ Answer: C) Three-address code
Solution:
It closely matches register-level operations.
73.if x < y goto L1 is an example of:
A) Arithmetic TAC
B) Control TAC
C) Boolean TAC
D) Logical TAC
✅ Answer: B) Control TAC
Solution:
Conditional transfer of control.
74.
In three-address code, which statement represents pointer arithmetic?
A) t1 = &a
B) t2 = *p
C) p = p + 1
D) return p
✅ Answer: C) p = p + 1
Solution:
Incrementing a pointer is pointer arithmetic.
75.
For nested loops, backpatching handles:
A) Variable lifetimes
B) Jump addresses for loops
C) Function calls
D) Parameter stack
✅ Answer: B) Jump addresses for loops
Solution:
Patching labels ensures correct looping control.
76.
Intermediate code for for(i=0;i<3;i++) uses how many labels?
A) 2
B) 3
C) 4
D) 5
✅ Answer: B) 3
Solution:
Initialization, condition, and increment need labels.
77.
Which IR is easiest to interpret directly?
A) Postfix
B) DAG
C) Three-address code
D) Syntax tree
✅ Answer: A) Postfix
Solution:
Postfix is easily evaluated using a stack.
78.
Expression x = a + b * c - d requires how many TACs?
A) 2
B) 3
C) 4
D) 5
✅ Answer: B) 3
Solution:t1 = b * c; t2 = a + t1; x = t2 - d.
79.
The TAC instruction t1 = y < z is used in:
A) Boolean expression evaluation
B) Constant folding
C) Loop unrolling
D) Array indexing
✅ Answer: A) Boolean expression evaluation
Solution:
Generates condition results for later jumps.
80.
Which IR allows common subexpression elimination?
A) Quadruple
B) DAG
C) Triple
D) Syntax tree
