La a a la a b la a ? the 3 rd symbol of the la

• Notes
• 27

This preview shows page 6 - 11 out of 27 pages.

LA( A a ) = LA( A b ) = LA( A λ ) = The 3 rd symbol of the LA strings provides sufficient information to discriminate which one of the A rules to use. { a abd , b abd , a bd , c a bcd , c b bcd , cbcd } { a abd , b abd , a bd } { c a bcd , c b bcd , c bcd } { a abd , a bcd } { b abd , b bcd } { a bd , b cd } /* 1 st symbol: { a, b } */ /* 1 st symbol: { c } */ /* 2 nd symbol: { aa , ab }; 3 rd symbol: { aab , abc } */ /* 2 nd symbol: { ba , bb }; 3 rd symbol: { bab , bbc } */ /* 2 nd symbol: { ab , bc }; 3 rd symbol: { abd , bcd } */

Subscribe to view the full document.

7 Lookahead Strings and Lookahead Sets Example 19.1.2. Given the following grammar G 2 : S ABCabcd , A a | λ , B b | λ , C c | λ LA( S ) = { abc abcd , ab abcd , ac abcd , bc abcd , a abcd , b abcd , c abcd , abcd } No lookahead symbol is required in selecting the only S rule A a LA( A a ) = { abc a bcd , ab abcd , ac abcd , a abcd } A λ LA( A λ ) = { bc abcd , b abcd , c abcd , abcd } The 4 th lookahead symbol is required in selecting the A rule B b LA( B b ) = { bc abcd , b abcd } B λ LA( B λ ) = { c abcd , abcd } The 1 st lookahead symbol is required in selecting the B rule C c LA( C c ) = { c abcd } C λ LA( C λ ) = { abcd } The 1 st lookahead symbol is required in selecting the C rule
8 FIRST, FOLLOW, and Lookahead Sets The lookahead set LA k ( A ) contains prefixes of length up to k of strings that can be derived from the variable A (and after) If variable A derives strings of length < k , the remainder of the lookahead strings comes from derivations that follow A in the production rules of the grammar. FIRST k ( A ) contains prefixes of length up to k of terminal symbols (directly ) derivable from A . FOLLOW k ( A ) contains prefixes of length up to k of terminal symbols that can follow the strings derivable from A . Defn. 19.2.1. Let G be a CFG. For every string u (V )* and k > 0, the set FIRST k ( u ) is defined by FIRST k ( u ) = trunc k ( { x | u x , x * } ) where trunc k ( X ) = { u | u X w/ length( u ) k * or uv X w/ length( u ) = k }

Subscribe to view the full document.

9 FIRST, FOLLOW, and Lookahead Sets Defn. 19.2.3 . Let G be a CFG. For every A V and k > 0, the set FOLLOW k ( A ) is defined by FOLLOW k ( A ) = { x | S uAv and x FIRST k ( v ) } Example 19.2.1 . Given G 2 (in Example 19.1.2), S ABCabcd , A a | λ , B b | λ , C c | λ where ABC { abc , ab , ac , bc , a , b , c , λ } FIRST 1 ( ABC ) = FIRST 2 ( ABC ) = FIRST 3 ( S ) = Example 19.2.2 . FOLLOW 1 ( S ) = FOLLOW 1 ( A ) = FOLLOW 1 ( B ) = * { a , b , c , λ } { ab , ac , bc , a , b , c , λ } { abc , ab a , ac a , bc a , a ab , b ab , c ab } { λ } FOLLOW 2 ( S ) = { λ } { b , c , a } FOLLOW 2 ( A ) = { bc , ba , ca , ab } { c , a } FOLLOW 2 ( B ) = { ca , ab } { a } FOLLOW 2 ( C ) = { ab }

Subscribe to view the full document.

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