CSE 340 EXAM 1 QUESTIONS WITH
ANSWERS AND EXPLANATIONS
Question 1. A parser/semantic implementation shows this defect: Use one flat expression production that
gives + and * identical structural status and hope the evaluator chooses later. Which named idea is the
clearest correction?
A. Operator associativity in grammar
B. Operator precedence in grammar
C. Parse tree
D. Leftmost derivation
Correct Answer: B. Operator precedence in grammar
Explanation: Operator precedence in grammar is the direct match. Place multiplication and addition in different grammar
levels so multiplication is nested lower in the expression hierarchy.
Question 2. A reviewer wants evidence that Abstract syntax tree is implemented correctly. Which check is
most persuasive?
A. Compare parse tree and AST for the same expression and verify the AST retains all semantically relevant structure.
B. Apply the transition rules to a short program and verify each intermediate configuration is justified.
C. Trace a declaration followed by assignment and verify only the store value changes when the binding stays constant.
D. Run semantic analysis on well-typed and ill-typed assignments and verify the latter is rejected.
Correct Answer: A. Compare parse tree and AST for the same expression and verify the AST retains all
semantically relevant structure.
Explanation: Compare parse tree and AST for the same expression and verify the AST retains all semantically relevant
structure. This directly validates Abstract syntax tree; the alternatives test different language properties.
Question 3. A source-language tool is being revised because Multiplication must bind more tightly than
addition without relying on a post-parsing convention. Which implementation decision best fits?
A. Construct the parse tree and compare parent-child production structure rather than the order in which nodes were
expanded.
B. Define nonterminals and productions in a context-free grammar to describe the recursive syntactic structure.
C. At each derivation step, replace the leftmost remaining nonterminal using one grammar production.
D. Place multiplication and addition in different grammar levels so multiplication is nested lower in the expression
hierarchy.
Correct Answer: D. Place multiplication and addition in different grammar levels so multiplication is nested lower
in the expression hierarchy.
Explanation: Place multiplication and addition in different grammar levels so multiplication is nested lower in the expression
hierarchy. The desired binding strength is encoded directly in the parse structure.
,Question 4. A compiler team chooses Environment and store distinction because Two variables may refer
to locations whose contents change while the variable-to-location bindings remain fixed. Which outcome
best justifies that choice?
A. Semantic analysis and interpretation operate on a simpler representation focused on meaningful constructs.
B. Binding structure and mutable state are represented separately, clarifying assignment semantics.
C. Meaning-related computation stays systematically connected to the grammar that recognized the construct.
D. Program behavior becomes a sequence of formally described computation steps.
Correct Answer: B. Binding structure and mutable state are represented separately, clarifying assignment
semantics.
Explanation: Binding structure and mutable state are represented separately, clarifying assignment semantics. This is the
central value of Environment and store distinction in the stated situation.
Question 5. A reviewer wants evidence that Context-free grammar is implemented correctly. Which check
is most persuasive?
A. Search for one concrete sentence with two distinct parse trees or derivations.
B. Parse a mixed expression such as a+b*c and verify multiplication forms the deeper subtree.
C. Parse a three-operator chain and inspect the nesting direction in the resulting tree.
D. Derive several valid strings and confirm that invalid structural combinations cannot be derived.
Correct Answer: D. Derive several valid strings and confirm that invalid structural combinations cannot be
derived.
Explanation: Derive several valid strings and confirm that invalid structural combinations cannot be derived. This directly
validates Context-free grammar; the alternatives test different language properties.
Question 6. A compiler front end must satisfy this requirement: A predictive recursive-descent parser
loops immediately on a production like E -> E + T | T. Which approach best addresses it?
A. Compute the FIRST set for that nonterminal, including epsilon when the nonterminal can derive the empty string.
B. Compute the FOLLOW set of the nonterminal from its grammatical contexts.
C. Rewrite the left-recursive production into an equivalent form that consumes input before recurring.
D. Implement one parsing routine per nonterminal, using lookahead to choose among productions.
Correct Answer: C. Rewrite the left-recursive production into an equivalent form that consumes input before
recurring.
Explanation: Rewrite the left-recursive production into an equivalent form that consumes input before recurring. The parser
can make progress and becomes suitable for top-down predictive implementation.
Question 7. A reviewer wants evidence that Parse tree is implemented correctly. Which check is most
persuasive?
A. Parse a three-operator chain and inspect the nesting direction in the resulting tree.
B. Build trees for both derivations and verify whether their labeled structure is identical.
C. Derive several valid strings and confirm that invalid structural combinations cannot be derived.
D. Record each sentential form and verify that the changed symbol was the leftmost nonterminal.
Correct Answer: B. Build trees for both derivations and verify whether their labeled structure is identical.
Explanation: Build trees for both derivations and verify whether their labeled structure is identical. This directly validates Parse
tree; the alternatives test different language properties.
, Question 8. An implementation behaves incorrectly because Use a single routine that ignores nonterminal
boundaries and scans until end-of-file. Which concept is missing or misapplied?
A. Recursive-descent parser
B. FOLLOW set
C. LL(1) predictive table
D. FIRST set
Correct Answer: A. Recursive-descent parser
Explanation: Recursive-descent parser is the direct match. Implement one parsing routine per nonterminal, using lookahead to
choose among productions.
Question 9. Why is Grammar ambiguity particularly useful when A single token sequence can be parsed
into two structurally different expression trees.?
A. The parse tree represents the specified left-associative evaluation structure.
B. Recursive language structure can be expressed directly and parsed independently of particular source strings.
C. Ambiguity exposes multiple possible syntactic interpretations that later phases cannot resolve without extra rules.
D. The derivation order is unambiguous and can be compared with a corresponding parse tree.
Correct Answer: C. Ambiguity exposes multiple possible syntactic interpretations that later phases cannot resolve
without extra rules.
Explanation: Ambiguity exposes multiple possible syntactic interpretations that later phases cannot resolve without extra rules.
This is the central value of Grammar ambiguity in the stated situation.
Question 10. Reviewers observe that Allow multiple competing productions in the same table cell and
choose randomly during parsing. Which language-processing principle should guide the fix?
A. FIRST set
B. Recursive-descent parser
C. FOLLOW set
D. LL(1) predictive table
Correct Answer: D. LL(1) predictive table
Explanation: LL(1) predictive table is the direct match. Construct an LL(1) table whose cells contain at most one production for
each nonterminal/lookahead pair.
Question 11. For the stated requirement, what is the strongest advantage of Syntax-directed translation?
A. Ill-formed programs can be rejected before execution and runtime states need not handle that mismatch.
B. Semantic analysis and interpretation operate on a simpler representation focused on meaningful constructs.
C. Meaning-related computation stays systematically connected to the grammar that recognized the construct.
D. Program behavior becomes a sequence of formally described computation steps.
Correct Answer: C. Meaning-related computation stays systematically connected to the grammar that recognized
the construct.
Explanation: Meaning-related computation stays systematically connected to the grammar that recognized the construct. This
is the central value of Syntax-directed translation in the stated situation.
ANSWERS AND EXPLANATIONS
Question 1. A parser/semantic implementation shows this defect: Use one flat expression production that
gives + and * identical structural status and hope the evaluator chooses later. Which named idea is the
clearest correction?
A. Operator associativity in grammar
B. Operator precedence in grammar
C. Parse tree
D. Leftmost derivation
Correct Answer: B. Operator precedence in grammar
Explanation: Operator precedence in grammar is the direct match. Place multiplication and addition in different grammar
levels so multiplication is nested lower in the expression hierarchy.
Question 2. A reviewer wants evidence that Abstract syntax tree is implemented correctly. Which check is
most persuasive?
A. Compare parse tree and AST for the same expression and verify the AST retains all semantically relevant structure.
B. Apply the transition rules to a short program and verify each intermediate configuration is justified.
C. Trace a declaration followed by assignment and verify only the store value changes when the binding stays constant.
D. Run semantic analysis on well-typed and ill-typed assignments and verify the latter is rejected.
Correct Answer: A. Compare parse tree and AST for the same expression and verify the AST retains all
semantically relevant structure.
Explanation: Compare parse tree and AST for the same expression and verify the AST retains all semantically relevant
structure. This directly validates Abstract syntax tree; the alternatives test different language properties.
Question 3. A source-language tool is being revised because Multiplication must bind more tightly than
addition without relying on a post-parsing convention. Which implementation decision best fits?
A. Construct the parse tree and compare parent-child production structure rather than the order in which nodes were
expanded.
B. Define nonterminals and productions in a context-free grammar to describe the recursive syntactic structure.
C. At each derivation step, replace the leftmost remaining nonterminal using one grammar production.
D. Place multiplication and addition in different grammar levels so multiplication is nested lower in the expression
hierarchy.
Correct Answer: D. Place multiplication and addition in different grammar levels so multiplication is nested lower
in the expression hierarchy.
Explanation: Place multiplication and addition in different grammar levels so multiplication is nested lower in the expression
hierarchy. The desired binding strength is encoded directly in the parse structure.
,Question 4. A compiler team chooses Environment and store distinction because Two variables may refer
to locations whose contents change while the variable-to-location bindings remain fixed. Which outcome
best justifies that choice?
A. Semantic analysis and interpretation operate on a simpler representation focused on meaningful constructs.
B. Binding structure and mutable state are represented separately, clarifying assignment semantics.
C. Meaning-related computation stays systematically connected to the grammar that recognized the construct.
D. Program behavior becomes a sequence of formally described computation steps.
Correct Answer: B. Binding structure and mutable state are represented separately, clarifying assignment
semantics.
Explanation: Binding structure and mutable state are represented separately, clarifying assignment semantics. This is the
central value of Environment and store distinction in the stated situation.
Question 5. A reviewer wants evidence that Context-free grammar is implemented correctly. Which check
is most persuasive?
A. Search for one concrete sentence with two distinct parse trees or derivations.
B. Parse a mixed expression such as a+b*c and verify multiplication forms the deeper subtree.
C. Parse a three-operator chain and inspect the nesting direction in the resulting tree.
D. Derive several valid strings and confirm that invalid structural combinations cannot be derived.
Correct Answer: D. Derive several valid strings and confirm that invalid structural combinations cannot be
derived.
Explanation: Derive several valid strings and confirm that invalid structural combinations cannot be derived. This directly
validates Context-free grammar; the alternatives test different language properties.
Question 6. A compiler front end must satisfy this requirement: A predictive recursive-descent parser
loops immediately on a production like E -> E + T | T. Which approach best addresses it?
A. Compute the FIRST set for that nonterminal, including epsilon when the nonterminal can derive the empty string.
B. Compute the FOLLOW set of the nonterminal from its grammatical contexts.
C. Rewrite the left-recursive production into an equivalent form that consumes input before recurring.
D. Implement one parsing routine per nonterminal, using lookahead to choose among productions.
Correct Answer: C. Rewrite the left-recursive production into an equivalent form that consumes input before
recurring.
Explanation: Rewrite the left-recursive production into an equivalent form that consumes input before recurring. The parser
can make progress and becomes suitable for top-down predictive implementation.
Question 7. A reviewer wants evidence that Parse tree is implemented correctly. Which check is most
persuasive?
A. Parse a three-operator chain and inspect the nesting direction in the resulting tree.
B. Build trees for both derivations and verify whether their labeled structure is identical.
C. Derive several valid strings and confirm that invalid structural combinations cannot be derived.
D. Record each sentential form and verify that the changed symbol was the leftmost nonterminal.
Correct Answer: B. Build trees for both derivations and verify whether their labeled structure is identical.
Explanation: Build trees for both derivations and verify whether their labeled structure is identical. This directly validates Parse
tree; the alternatives test different language properties.
, Question 8. An implementation behaves incorrectly because Use a single routine that ignores nonterminal
boundaries and scans until end-of-file. Which concept is missing or misapplied?
A. Recursive-descent parser
B. FOLLOW set
C. LL(1) predictive table
D. FIRST set
Correct Answer: A. Recursive-descent parser
Explanation: Recursive-descent parser is the direct match. Implement one parsing routine per nonterminal, using lookahead to
choose among productions.
Question 9. Why is Grammar ambiguity particularly useful when A single token sequence can be parsed
into two structurally different expression trees.?
A. The parse tree represents the specified left-associative evaluation structure.
B. Recursive language structure can be expressed directly and parsed independently of particular source strings.
C. Ambiguity exposes multiple possible syntactic interpretations that later phases cannot resolve without extra rules.
D. The derivation order is unambiguous and can be compared with a corresponding parse tree.
Correct Answer: C. Ambiguity exposes multiple possible syntactic interpretations that later phases cannot resolve
without extra rules.
Explanation: Ambiguity exposes multiple possible syntactic interpretations that later phases cannot resolve without extra rules.
This is the central value of Grammar ambiguity in the stated situation.
Question 10. Reviewers observe that Allow multiple competing productions in the same table cell and
choose randomly during parsing. Which language-processing principle should guide the fix?
A. FIRST set
B. Recursive-descent parser
C. FOLLOW set
D. LL(1) predictive table
Correct Answer: D. LL(1) predictive table
Explanation: LL(1) predictive table is the direct match. Construct an LL(1) table whose cells contain at most one production for
each nonterminal/lookahead pair.
Question 11. For the stated requirement, what is the strongest advantage of Syntax-directed translation?
A. Ill-formed programs can be rejected before execution and runtime states need not handle that mismatch.
B. Semantic analysis and interpretation operate on a simpler representation focused on meaningful constructs.
C. Meaning-related computation stays systematically connected to the grammar that recognized the construct.
D. Program behavior becomes a sequence of formally described computation steps.
Correct Answer: C. Meaning-related computation stays systematically connected to the grammar that recognized
the construct.
Explanation: Meaning-related computation stays systematically connected to the grammar that recognized the construct. This
is the central value of Syntax-directed translation in the stated situation.