Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 30
Q901:
The token definitions in YACC are written using which directive?
A. %token
B. %define
C. %grammar
D. %lex
Correct Answer:
A
Chapter: 30
Q902:
Flex is primarily used for:
A. Lexical analysis
B. Syntax analysis
C. Semantic analysis
D. Code generation
Correct Answer:
A
Chapter: 30
Q903:
The regular expression "+" in Flex returns which token?
A. PLUS
B. MINUS
C. TIMES
D. DIVIDE
Correct Answer:
A
Chapter: 30
Q904:
In the calculator example, LPAREN and RPAREN tokens represent:
A. Left and right parentheses
B. Addition and subtraction
C. Multiplication and division
D. Numbers
Correct Answer:
A
Chapter: 31
Q905:
Beyond syntax analysis, questions depend on ________, not just parts of speech.
A. Values
B. Tokens
C. Keywords
D. Symbols
Correct Answer:
A
Chapter: 31
Q906:
Context-sensitive analysis answers may involve ________.
A. Computation
B. Syntax parsing
C. Lexical analysis
D. Semantic error detection
Correct Answer:
A
Chapter: 31
Q907:
Which formal method is popular for context-sensitive analysis?
A. Attribute grammars
B. Context-free grammars
C. Regular expressions
D. Finite automata
Correct Answer:
A
Chapter: 31
Q908:
Attribute grammars augment a CFG with ________.
A. Rules to compute values
B. Additional terminals
C. Extra non-terminals
D. Parsing tables
Correct Answer:
A
Chapter: 31
Q909:
In the grammar for signed binary numbers (SBN), the start symbol is ________.
A. Number
B. Sign
C. List
D. Bit
Correct Answer:
A
Chapter: 31
Q910:
In the SBN grammar, Sign can be ________ or ________.
A. +, –
B. 0, 1
C. A, B
D. True, False
Correct Answer:
A
Chapter: 31
Q911:
The string “–1” can be derived from the grammar as:
A. Number → Sign List → – Bit → – 1
B. Number → List Sign → – Bit → – 1
C. Number → Bit Sign → – Bit → – 1
D. Number → Sign Bit → – Bit → – 1
Correct Answer:
A
Chapter: 31
Q912:
Attributes associated with nodes in parse tree are called ________.
A. Synthesized and inherited attributes
B. Terminal and non-terminal
C. Left and right attributes
D. Syntactic and semantic attributes
Correct Answer:
A
Chapter: 31
Q913:
Synthesized attributes flow ________ in the parse tree.
A. Bottom-up
B. Top-down
C. Sideways
D. Random
Correct Answer:
A
Chapter: 31
Q914:
Inherited attributes flow ________ in the parse tree.
A. Top-down and laterally
B. Bottom-up
C. Only top-down
D. Only laterally
Correct Answer:
A
Chapter: 31
Q915:
In the SBN attributed grammar, Sign.neg is true if Sign is ________.
A. –
B. +
D. 1
Correct Answer:
A
Chapter: 31
Q916:
For the production List0 → List1 Bit, List1.pos is assigned as ________.
A. List0.pos + 1
B. List0.pos – 1
C. List0.pos
D. Bit.pos
Correct Answer:
A
Chapter: 31
Q917:
Bit.val for bit '1' is computed as ________.
A. 2^Bit.pos
B. 1
D. Bit.pos
Correct Answer:
A
Chapter: 31
Q918:
The decimal value of the signed binary number “-101” is ________.
A. –5
B. 5
C. –7
D. 7
Correct Answer:
A
Chapter: 31
Q919:
The inherited attribute in the attributed parse tree example is ________.
A. pos
B. val
C. neg
D. Number.val
Correct Answer:
A
Chapter: 31
Q920:
The synthesized attribute in the attributed parse tree example is ________.
A. val
B. pos
C. neg
D. Sign.neg
Correct Answer:
A