Q.1 What is the primary purpose of Three Address Code (TAC) in compiler design?
To optimize machine instructions
To provide an intermediate representation
To directly execute code
To parse the source code
Explanation - TAC serves as an intermediate representation that simplifies translation from high-level code to machine code.
Correct answer is: To provide an intermediate representation
Q.2 In Three Address Code, each statement typically contains how many addresses?
Two
Three
Four
Variable
Explanation - Each TAC instruction has at most three addresses—two operands and one result.
Correct answer is: Three
Q.3 Which of the following is an example of a TAC assignment?
t1 = a + b
if a < b goto L1
param a
call f, n
Explanation - Assignments in TAC usually take the form result = operand1 op operand2.
Correct answer is: t1 = a + b
Q.4 In TAC, temporary variables are often denoted as:
x1, x2
T1, T2
temp1, temp2
t1, t2
Explanation - Conventionally, TAC temporaries are denoted as t1, t2, t3, etc.
Correct answer is: t1, t2
Q.5 Which TAC instruction represents a conditional jump?
goto L1
t1 = a + b
if a < b goto L1
return x
Explanation - Conditional jumps in TAC use relational operators to decide control flow.
Correct answer is: if a < b goto L1
Q.6 In compiler phases, TAC is usually generated during:
Lexical analysis
Syntax analysis
Intermediate code generation
Optimization
Explanation - TAC is produced during the intermediate code generation phase of the compiler.
Correct answer is: Intermediate code generation
Q.7 The TAC instruction 'param x' means:
Store parameter x
Return x
Pass x as a parameter
Assign x to a variable
Explanation - In TAC, 'param x' means that x is being passed as an argument to a function call.
Correct answer is: Pass x as a parameter
Q.8 Which of the following TAC instructions represents an unconditional jump?
goto L1
if x < y goto L2
call f, n
return x
Explanation - The 'goto' statement without condition is an unconditional jump in TAC.
Correct answer is: goto L1
Q.9 The instruction 'call f, n' in TAC means:
Call function f with n parameters
Call function f and assign result to n
Assign f to n
Jump to label n
Explanation - In TAC, 'call f, n' indicates calling function f with n arguments.
Correct answer is: Call function f with n parameters
Q.10 Which representation is closer to machine code?
Abstract Syntax Tree
Parse Tree
Three Address Code
High-level code
Explanation - TAC is an intermediate representation closer to machine code than AST or parse trees.
Correct answer is: Three Address Code
Q.11 What does 't1 = -a' represent in TAC?
Unary operation
Binary operation
Jump instruction
Function call
Explanation - The TAC instruction 't1 = -a' represents a unary minus operation.
Correct answer is: Unary operation
Q.12 Why are temporaries needed in TAC?
To store intermediate results
To replace registers
To parse expressions
To hold constants only
Explanation - Temporaries hold intermediate results during expression evaluation.
Correct answer is: To store intermediate results
Q.13 Which TAC instruction represents returning a value from a function?
return
return x
call f, n
param x
Explanation - In TAC, 'return x' means returning the value x from the function.
Correct answer is: return x
Q.14 The advantage of TAC is:
Easier parsing
Hardware independence
Direct execution
Eliminates lexical analysis
Explanation - TAC provides a hardware-independent representation useful for optimization and code generation.
Correct answer is: Hardware independence
Q.15 In TAC, the instruction 't1 = a * b' means:
Multiply a and b, store in t1
Assign a to b
Add a and b
Compare a and b
Explanation - TAC expresses arithmetic directly; here multiplication result is stored in t1.
Correct answer is: Multiply a and b, store in t1
Q.16 Which of the following is NOT a form of TAC?
x = y op z
x = op y
goto L
y = call x, z
Explanation - Valid TAC function call syntax is 'call f, n', not 'y = call x, z'.
Correct answer is: y = call x, z
Q.17 How does TAC handle complex expressions like (a+b)*(c-d)?
Direct single instruction
Break into multiple TAC instructions with temporaries
Evaluate at runtime only
Use recursion
Explanation - TAC decomposes complex expressions into simpler instructions using temporaries.
Correct answer is: Break into multiple TAC instructions with temporaries
Q.18 The label L1 in TAC is used for:
Storing data
Marking jump targets
Declaring variables
Defining functions
Explanation - Labels mark locations for control flow jumps in TAC.
Correct answer is: Marking jump targets
Q.19 Which TAC instruction is used for procedure return?
call f, n
param x
return
goto L
Explanation - In TAC, 'return' without arguments is used for procedure (no value) return.
Correct answer is: return
Q.20 What does 't1 = a < b' mean in TAC?
Assign true/false to t1 depending on comparison
Assign b to a
Jump to label
Return a if less than b
Explanation - TAC supports relational operators that evaluate to boolean values.
Correct answer is: Assign true/false to t1 depending on comparison
Q.21 Which of these is a binary operation TAC form?
x = op y
x = y op z
goto L
param x
Explanation - Binary operations take two operands and produce one result, like 't1 = a + b'.
Correct answer is: x = y op z
Q.22 In TAC, 't1 = &a' represents:
Value of a
Address of a
Negation of a
Increment of a
Explanation - TAC uses '&' to denote the address-of operation.
Correct answer is: Address of a
Q.23 Which TAC instruction loads a value indirectly?
t1 = *p
t1 = p
t1 = &p
t1 = -p
Explanation - '*p' means dereferencing pointer p to get the value stored at that location.
Correct answer is: t1 = *p
Q.24 What does 't1 = a[i]' mean in TAC?
Assign array size
Access ith element of array a
Assign a to i
Pointer dereference
Explanation - Array access is represented as result = base[index] in TAC.
Correct answer is: Access ith element of array a
Q.25 The TAC instruction 'a[i] = t1' means:
Assign i to a
Assign a to t1
Store t1 into ith element of a
Increment a[i]
Explanation - This TAC form represents storing a temporary value into an array element.
Correct answer is: Store t1 into ith element of a
