Skip to main content

Compiler Construction MCQs with Answers

Practice important Compiler Construction MCQs with answers and explanations.

Chapter: 32
Q941:
For List → Bit, List.val is assigned as ________.
A. Bit.val
B. List.val
C. Bit.pos
D. List.pos
Correct Answer: A
Chapter: 32
Q942:
For List0 → List1 Bit, List0.val is computed as ________.
A. 2 × List1.val + Bit.val
B. List1.val + Bit.val
C. List1.val – Bit.val
D. Bit.val – List1.val
Correct Answer: A
Chapter: 32
Q943:
The LR(1) parser's "shift" action pushes token and ________ onto the stack.
A. State index i
B. Grammar symbol A
C. Next token
D. Parsing rule
Correct Answer: A
Chapter: 32
Q944:
In the LR(1) parser, Goto[s,A] gives the ________.
A. Next state after reduction
B. Previous state
C. Current token
D. Current state
Correct Answer: A
Chapter: 33
Q945:
In the ad-hoc scheme, the parser passes values of attributes from one snippet to ________.
A. Another snippet
B. The scanner
C. The lexer
D. The optimizer
Correct Answer: A
Chapter: 33
Q946:
YACC notation for snippets is adopted to ________.
A. Pass attribute values
B. Optimize code
C. Generate machine code
D. Handle syntax errors
Correct Answer: A
Chapter: 33
Q947:
In the LR(1) parser skeleton, the stack stores pairs of 〈symbol, state〉 which can be replaced with ________.
A. Triples 〈value, symbol, state〉
B. Triples 〈token, state, symbol〉
C. Triplets 〈state, symbol, value〉
D. Pairs 〈value, state〉
Correct Answer: A
Chapter: 33
Q948:
When pushing onto the stack after reduction in the ad-hoc scheme, the parser pushes ________ along with symbol.
A. Value
B. Token
C. State
D. Next token
Correct Answer: A
Chapter: 33
Q949:
The notation 〈value, symbol, state〉 on the parser stack is used to implement ________.
A. Attribute value passing
B. Lexical analysis
C. Code generation
D. Syntax error detection
Correct Answer: A
Chapter: 34
Q950:
In YACC, the token declarations start with the keyword ________.
A. %token
B. %union
C. %type
D. %left
Correct Answer: A
Chapter: 34
Q951:
Which token is used in the YACC calculator grammar to represent a number?
A. NUMBER
B. LPAREN
C. RPAREN
D. EQUAL
Correct Answer: A
Chapter: 34
Q952:
The YACC operator to specify precedence and associativity for tokens is ________.
A. %left
B. %token
C. %type
D. %union
Correct Answer: A
Chapter: 34
Q953:
The code snippet {$ $= $1 + $3;} in YACC indicates addition of which elements?
A. First and third expr symbols
B. First and second tokens
C. Second and third tokens
D. First and second expr
Correct Answer: A
Chapter: 34
Q954:
In the production expr : expr MINUS expr {$ $= $1 - $3;}, $1 and $3 refer to ________.
A. The first and third expr values
B. The first and second tokens
C. The second and third tokens
D. The second and third expr
Correct Answer: A
Chapter: 34
Q955:
In YACC, the notation $$ refers to the ________.
A. Left hand side symbol value
B. Right hand side first token
C. Right hand side second token
D. Right hand side third token
Correct Answer: A
Chapter: 34
Q956:
In YACC, the type of value stored in the parse stack can be declared using ________.
A. %union
B. %token
C. %left
D. %nonassoc
Correct Answer: A
Chapter: 34
Q957:
The dummy token used to handle unary minus precedence in the example is ________.
A. UMINUS
B. MINUS
C. PLUS
D. TIMES
Correct Answer: A
Chapter: 34
Q958:
In the grammar rule expr : LPAREN expr RPAREN {$ $= $2;}, $2 refers to the value of ________.
A. expr inside parentheses
B. LPAREN token
C. RPAREN token
D. The entire expression
Correct Answer: A
Chapter: 34
Q959:
The intermediate representation (IR) in compilers is mainly used to ________.
A. Pass information between passes
B. Generate executable code
C. Perform lexical analysis
D. Detect syntax errors
Correct Answer: A
Chapter: 34
Q960:
The symbol table is considered part of the ________ in compiler design.
A. Intermediate Representation
B. Lexical Analyzer
C. Parser
D. Code Generator
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Compiler Construction

🚀 Start Quiz Now