Skip to main content

Compiler Construction MCQs with Answers

Practice important Compiler Construction MCQs with answers and explanations.

Chapter: 38
Q1021:
The expression "if x relop y goto L" executes the statement with label L if ______ is true.
A. x relop y
B. y relop x
C. x = y
D. y = x
Correct Answer: A
Chapter: 38
Q1022:
Indexed assignment in the form x = y[i] means:
A. set x to value at location y
B. set x to value at location i
C. set x to value in location i memory units beyond y
D. set x to value in location y plus i
Correct Answer: C
Chapter: 38
Q1023:
The statement x[i] = y means:
A. set x[i] to y
B. set contents of location i beyond x to y
C. set y to x[i]
D. set x to y
Correct Answer: B
Chapter: 38
Q1024:
In syntax-directed translation, the attribute E.true represents:
A. label for true evaluation
B. label for false evaluation
C. next statement label
D. start label
Correct Answer: A
Chapter: 38
Q1025:
For the statement if a < b then goto E.true else goto E.false, which statement is executed when a is less than b?
A. goto E.true
B. goto E.false
C. next instruction
D. error
Correct Answer: A
Chapter: 38
Q1026:
In syntax-directed translation for S → if E then S1 else S2, which attribute is used for S1.next?
A. S.next
B. E.true
C. E.false
D. newlabel()
Correct Answer: A
Chapter: 38
Q1027:
In the while loop syntax-directed translation, S.begin represents:
A. the start label of the loop
B. the exit label
C. the true label
D. the false label
Correct Answer: A
Chapter: 38
Q1028:
The function newlabel() in syntax-directed translation is used to:
A. create a new temporary variable
B. create a new symbolic label
C. generate a new operator
D. generate a new operand
Correct Answer: B
Chapter: 38
Q1029:
The statement gen('goto' S.next) in syntax-directed translation generates code for:
A. unconditional jump
B. conditional jump
C. assignment
D. label definition
Correct Answer: A
Chapter: 38
Q1030:
The code for a while loop in syntax-directed translation includes which of the following?
A. loop start label
B. boolean expression code
C. jump back to loop start
D. all of the above
Correct Answer: D
Chapter: 39
Q1031:
What are the two primary purposes of boolean expressions in programming languages?
A. Computing logical values and conditional flow
B. Storing data and loops
C. Arithmetic calculations and strings
D. Input/output operations
Correct Answer: A
Chapter: 39
Q1032:
In the grammar of boolean expressions, what does E → E or E represent?
A. Logical OR operation
B. Logical AND operation
C. Negation
D. Parenthesis grouping
Correct Answer: A
Chapter: 39
Q1033:
Which code is generated for the rule E → id1 relop id2 in syntax-directed translation?
A. if id1 relop id2 goto E.true and goto E.false
B. if id1 relop id2 goto E.true only
C. goto E.false only
D. no code generated
Correct Answer: A
Chapter: 39
Q1034:
What does the function makelist(i) do in backpatching?
A. Creates a list containing quadruple index i
B. Merges two lists
C. Emits a jump statement
D. Returns the next label
Correct Answer: A
Chapter: 39
Q1035:
In backpatching, what is the purpose of the merge(p1, p2) function?
A. Concatenates two lists of goto statements
B. Creates a new list
C. Generates labels
D. Fills jump targets
Correct Answer: B
Chapter: 39
Q1036:
What is the role of the backpatch(p, i) function?
A. Inserts label i as the target for each goto on list p
B. Generates a new quadruple
C. Merges two lists
D. Deletes a list
Correct Answer: A
Chapter: 39
Q1037:
In the boolean expression E → E1 and E2, what is assigned to E1.true?
A. A new label
B. E.false
C. E.true
D. Next quadruple
Correct Answer: A
Chapter: 39
Q1038:
Fill in the blank: The semantic action { M.quad = nextquad() } associates M.quad with the _______.
A. Index of the next quadruple
B. Number of jumps
C. Label name
D. Variable
Correct Answer: A
Chapter: 39
Q1039:
Which statement correctly describes E.true and E.false in syntax-directed translation?
A. Lists of jumps with targets to be backpatched
B. Variable names
C. Operators
D. Boolean values
Correct Answer: A
Chapter: 39
Q1040:
What does the generated code for the expression "a < b or c < d and e < f" include?
A. Multiple conditional gotos with labels
B. Single goto statement
C. Only if statements
D. No control flow
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Compiler Construction

🚀 Start Quiz Now