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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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 conict because if we're in A, one token lookahead isn't sufcient 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

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online