Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 34
Q961:
The YACC directive %nonassoc is used to declare tokens with ________.
A. No associativity
B. Left associativity
C. Right associativity
D. Both left and right
Correct Answer:
A
Chapter: 34
Q962:
In YACC, %left PLUS MINUS means that PLUS and MINUS have ________.
A. Left associativity
B. Right associativity
C. No associativity
D. Nonassociativity
Correct Answer:
A
Chapter: 35
Q963:
IRs fall into how many organizational categories?
A. 2
B. 3
C. 4
D. 5
Correct Answer:
B
Chapter: 35
Q964:
Which of the following is NOT an organizational category of IRs?
A. Graphical IRs
B. Linear IRs
C. Procedural IRs
D. Hybrid IRs
Correct Answer:
C
Chapter: 35
Q965:
Graphical IRs encode compiler knowledge in a ________.
A. graph
B. tree
C. list
D. stack
Correct Answer:
A
Chapter: 35
Q966:
Linear IRs resemble _______ for some abstract machine.
A. pseudo-code
B. assembly code
C. machine code
D. source code
Correct Answer:
A
Chapter: 35
Q967:
Hybrid IRs combine elements of ______ and ______.
A. linear and procedural
B. graphical and procedural
C. graphical and linear
D. stack and graph
Correct Answer:
C
Chapter: 35
Q968:
Parse trees are primarily used as an IR in ________.
A. parsing and attribute grammar
B. code generation
C. lexical analysis
D. optimization
Correct Answer:
A
Chapter: 35
Q969:
Abstract Syntax Trees (AST) remove _______ nodes compared to parse trees.
A. essential
B. extraneous
C. semantic
D. syntactic
Correct Answer:
B
Chapter: 35
Q970:
Which IR avoids duplication by contracting an AST?
A. Directed Acyclic Graph (DAG)
B. Parse Tree
C. Linear IR
D. Three-address code
Correct Answer:
A
Chapter: 35
Q971:
The main advantage of a DAG over an AST is that it _______.
A. avoids duplication
B. includes all parse details
C. uses more nodes
D. is less concise
Correct Answer:
A
Chapter: 35
Q972:
The semantic rule E → E1 + E2 in AST creation uses the function ______ to create a node.
A. mknode(‘+’, E1.nptr, E2.nptr)
B. mkleaf(‘+’, E1.nptr)
C. mknode(‘*’, E1.nptr, E2.nptr)
D. mkleaf(‘num’, E1.val)
Correct Answer:
A
Chapter: 35
Q973:
The function used to create leaf nodes in AST is called ______.
A. mkleaf
B. mknode
C. mkbranch
D. mkroot
Correct Answer:
A
Chapter: 35
Q974:
In YACC syntax, the semantic rule for E → E1 * E2 is written as ______.
A. $$.nptr = mknode(‘*’, $1.nptr, $3.nptr)
B. $$.nptr = mkleaf(‘*’, $1.nptr)
C. $$.nptr = mknode(‘+’, $1.nptr, $3.nptr)
D. $$.nptr = $1.nptr
Correct Answer:
A
Chapter: 35
Q975:
Three-address code is an example of which type of IR?
A. Linear IR
B. Graphical IR
C. Hybrid IR
D. Parse Tree
Correct Answer:
A
Chapter: 35
Q976:
Stack-machine code is also known as ______.
A. one-address code
B. two-address code
C. three-address code
D. no-address code
Correct Answer:
A
Chapter: 35
Q977:
Stack-machine code primarily uses ______ to operate on operands.
A. operand stack
B. registers
C. memory addresses
D. variables
Correct Answer:
A
Chapter: 35
Q978:
Smalltalk-80 and Java byte-codes are examples of ______ IR.
A. stack-machine
B. three-address
C. hybrid
D. parse tree
Correct Answer:
A
Chapter: 35
Q979:
In three-address code, the general form of an operation is ______.
A. x ← y op z
B. op x y z
C. y ← x op z
D. z ← x op y
Correct Answer:
A
Chapter: 35
Q980:
Linear IRs execute instructions in the order of ______.
A. appearance
B. dependency
C. parallel
D. random
Correct Answer:
A