
CSE 401/M501 18au Homework 2 - CFGs and LR Parsing
Due: Thursday, October 18 by 11 pm. Please use Gradescope (linked from the CSE 401/M501 web page) to submit your homework online. Gradescope's web site has several instructional videos and help pages to outline the process, and this guide has specific information about scanning and uploading pdf files containing assignments.
- Unreadable solutions cannot be graded--no blurry photos, poor contrast, or illegible handwriting, please.
- Type-written solutions are encouraged but not required.
- If possible, don't split the solution to a problem across a page break.
- (Aho, Sethi, Ullman) Consider the grammar:
S ::=a
Sb
S |b
Sa
S | ε
- Show that this grammar is ambiguous by constructing two distinct leftmost derivations for the sentence abab.
- Show that this grammar is ambiguous by constructing two distinct rightmost derivations for the sentence abab.
- Construct the corresponding parse trees for your derivations.
- (Aho, Sethi, Ullman) Given the following grammar:
S ::=(
L)
|x
L ::= L,
S | S
- Give a left-most derivation of
(x, (x, x))
. - Give a right-most derivation of
(x, (x, x))
. - Show the steps that a shift-reduce parser goes through when it parses
(x, x, x)
. That is, show the contents of the stack and remaining input at each step. - Suppose we replace the left-recursive production L::=L
,
S with a right-recursive one L::=S,
L. What general effect does this have on the depth of the stack during a shift-reduce parse? (You might work through the parse of(x, x, x)
again to see what changes.)
- Give a left-most derivation of
- (Appel) Write a grammar for English sentences using the words
time arrow banana flies like a an the fruit
and the semicolon. Be sure to include all the senses (noun, verb, etc.) of each word. Then show that this grammar is ambiguous by exhibiting more than one parse tree for the sentence "time flies like an arrow; fruit flies like a banana". (Hint: do not go overboard. This is not an exercise in computational linguistics or Natural Language Processing. If you've done "sentence diagrams" in grade school, that's the right level of complexity for the grammar here. If you are not familiar with sentence diagrams, wikipedia has an article that shows what we've got in mind - look at the later half of the article for example trees. Don't try to reproduce diagrams with exactly the same details, but that's the general idea.)
Computer Science & Engineering University of Washington Box 352350 Seattle, WA 98195-2350 (206) 543-1695 voice, (206) 543-2969 FAX
Comments to admin