# Ab ac ba bb bc ? c ? follow 2 s c cc ? 11 ll k

• Notes
• 27

This preview shows page 10 - 18 out of 27 pages.

ab , ac , ba , bb , bc , λ } { c , λ } FOLLOW 2 ( S ) = { c , cc , λ }

Subscribe to view the full document.

11 LL( K ) Grammars Theorem 19.2.5. Let G be a CFG. For every k > 0, A V, and rule A w = u 1 u 2 u n in P , i) LA k ( A ) = trunc k (FIRST k ( A ) FOLLOW k ( A )) ii) LA k ( A w ) = trunc k (FIRST k ( w ) FOLLOW k ( A )) = trunc k (FIRST k ( u 1 )…FIRST k ( u n ) FOLLOW k ( A ))
12 19.4. Construction of FIRST k Sets Algorithm 19.4.1 Construction of FIRST k Sets Input: a CFG G = ( V , , P , S ) 1. For each a , do F’ ( a ) := { a } 2. For each A V , do F ( A ) := 3. Repeat 3.1 for each A V, do F’ ( A ) := F ( A ) 3.2 for each rule A u 1 u 2 u n with n > 0 do F( A ) := F( A ) trunc k (F’( u 1 )F’( u 2 ) … F’( u n )) UNTIL F ( A ) = F’ { A }, A V 4. FIRST k ( A ) = F ( A ) { λ } if A λ P φ otherwise

Subscribe to view the full document.

14 19.4. Construction of FOLLOW k Sets Algorithm 19.5.1 Construction of FOLLOW k Sets Input: a CFG G = ( V , , P , S ), FIRST k (A) for every A V 1. FL( S ) := { λ } 2. for each A V – { S } , do FL( A ) := φ 3. repeat 3.1 for each A V, do FL’( A ) := FL( A ) 3.2 for each rule A w = u 1 u 2 u n with w * do 3.2.1. L := FL’( A ) 3.2.2. if u n V , then FL( u n ) := FL( u n ) L 3.2.3. for i := n – 1 to 1 do 3.2.3.1. L := trunc k (FIRST k ( u i +1 ) L ) 3.2.3.2. if u i V , then FL( u i ) := FL( u i ) L until FL( A ) = FL’{ A }, A V 4. FOLLOW k ( A ) = FL( A )

Subscribe to view the full document.

15 19.5. Construction of FOLLOW k Sets Example 19.5.1 Construct the FOLLOW 2 sets for the variables of Rule S A ## A aAd A BC B bBc C acC | ad λ λ λ λ λ ## ##, d # ad , ac ## ##, d #, dd ad , ac , ca ##, d # ##, d #, dd ##, d #, dd ad , ac , ca, cc ##, d #, dd ad , ac , ca, cc ##, d #, dd FL ( S ) FL ( A ) FL ( B ) FL ( C ) 0 1 { } { } 2 { } { } { } { } 3 { } { } { } { } 4 { } { } { } { } 5 { } { } { } { } { λ } φ φ φ φ φ FL ( A ) := FL ( A ) trunc 2 ({ # } { # } FL ’( S )) FL ( A ) := FL ( A ) trunc 2 ({ d } FL ’( A )) FL ( C ) := FL ( C ) FL ( A ) FL ( B ) := FL ( B ) trunc 2 (FIRST 2 ( C ) FL ’( A )) := FL ( B ) trunc 2 ({ ad , ac } FL ’( A )) FL ( B ) := FL ( B ) trunc 2 ({ c } FL ’( B )) FL ( C ) := FL ( C ) FL ( C ) Assignments * *

Subscribe to view the full document.

17 19.3 Strong LL( K ) Grammars In strong LL( k ) grammars 2200 A V , LA k ( A ) is partitioned by LA k ( A w i ), i 1 An endmarker # k is attached to the end of each string in the grammar to guarantee that every LA string contains exactly k symbols Definition 19.3.1 Let G = ( V , , P , S ) be a CFG w/ endmarker # k . G is strong
You've reached the end of this preview.
• Winter '12
• DennisNg
• Grammar, Context-free grammar, Bottom-up parsing, lookahead sets

{[ 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