{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw5soln

# hw5soln - LL(k Grammars Problem 1 First 1 α ={s 1 | α...

This preview shows pages 1–2. Sign up to view the full content.

HW 5 Sample Solution Problem 1 First(A) = { ( , a } First(B) = { ( , a } First(C) = { ), ',' } Follow(A) = { eof , ',' , ) } Follow(B) = { ) } Follow(C) = { ) } eof B => AC A C => epsilon B => AC B A => a ) C ( a , C => ,AC A => (B) Stack Content Input Buffer Next Action \$A (a,(a,a))\$ A=>(B) \$)B( (a,(a,a))\$ consume token \$)B a,(a,a))\$ B=>AC \$)CA a,(a,a))\$ A=>a \$)Ca a,(a,a))\$ consume token \$)C ,(a,a))\$ C=>,AC \$)CA, ,(a,a))\$ consume token \$)CA (a,a))\$ A=>(B) \$)C)B( (a,a))\$ consume token \$)C)B a,a))\$ B=>AC \$)C)CA a,a))\$ A=>a \$)C)Ca a,a))\$ consume token \$)C)C ,a))\$ C=>,AC \$)C)CA, ,a))\$ consume token \$)C)CA a))\$ A=>a \$)C)Ca a))\$ consume token \$)C)C ))\$ C=>epsilon \$)C) ))\$ consume token \$)C )\$ C=>epsilon \$) )\$ consume token \$ \$ accept

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: LL(k) Grammars Problem 1. First 1 ( α ) = {s 1 | α =>* s} First 2 ( α ) = {s 2 | α =>* s} First k ( α ) = {s k | α =>* s} and Follow 1 (A) = {s 1 | S =>* α As} Follow 2 (A) = {s k | S =>* α As} Follow k (A) = {s k | S =>* α As} where s i is a sequence of i tokens. Problem 2. A ::= B | C B ::= 11 C ::= 10 There's a ﬁrst/ﬁrst conﬂict because if we're in A, one token lookahead isn't sufﬁcient to determine if B or C is correct. Problem 3. A LL(0) grammar describes a static string. Imagine the parse table without columns for the tokens. Each nonterminal must transition to another nonterminal without looking at the lookahead token....
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern