• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 26 pages
Exam (elaborations)

Cse 340 Exam 1 Questions With Answers And Explanations

Document preview thumbnail
Preview 3 out of 26 pages

Cse 340 Exam 1 Questions With Answers And Explanations

Content preview

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.

Document information

Uploaded on
October 10, 2026
Number of pages
26
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$15.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Favorgrades
3.8
(199)
Sold
854
Followers
377
Items
57829
Last sold
1 week ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions