Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are...
Transcript of Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are...
![Page 1: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/1.jpg)
Example of Constructing aPredictive Parsing Table
![Page 2: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/2.jpg)
e → t e'e' → + t e'
| 𝜀
t → f t't' → * f t'
| 𝜀
f → ( e )| x| y
Grammar: first and follow sets:
Non-Terminal
first follow
e ‘(‘, ‘x’, ‘y’ $, ‘)’
e' ‘+’, 𝜀 $, ‘)’
t ‘(‘, ‘x’, ‘y’ ‘+’, $, ‘)’
t' ‘*’, 𝜀 ‘+’, $, ‘)’
f ‘(‘, ‘x’, ‘y’ ‘*’, ‘+’, ‘)’, $
![Page 3: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/3.jpg)
Non-Terminal
Input Symbol
x y + * ( ) $
e
e'
t
t'
f
Start with an empty parsing table; the rows arenon-terminals and the columns are terminals.
![Page 4: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/4.jpg)
e → t e'
first( t e' ) = ‘(‘, ‘x’, ‘y’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e'
e'
t
t'
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 5: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/5.jpg)
e → t e'
first( t e' ) = ‘(‘, ‘x’, ‘y’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e'
e'
t
t'
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 6: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/6.jpg)
e → t e'
first( t e' ) = ‘(‘, ‘x’, ‘y’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e'
t
t'
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 7: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/7.jpg)
e' → + t e'
first( + t e' ) = ‘+’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e'→ + t e'
t
t'
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 8: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/8.jpg)
e' → 𝜀
follow( e' ) = $, ‘)’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e'→ + t e' e' → 𝜀
t
t'
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 9: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/9.jpg)
e' → 𝜀
follow( e' ) = $, ‘)’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e'→ + t e' e' → 𝜀 e' → 𝜀
t
t'
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 10: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/10.jpg)
t → f t'
first( f t' ) = ‘(‘, ‘x’, ‘y’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e'→ + t e' e' → 𝜀 e' → 𝜀
t t→ f t'
t'
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 11: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/11.jpg)
t → f t'
first( f t' ) = ‘(‘, ‘x’, ‘y’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e'→ + t e' e' → 𝜀 e' → 𝜀
t t→ f t' t→ f t'
t'
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 12: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/12.jpg)
t → f t'
first( f t' ) = ‘(‘, ‘x’, ‘y’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e’→ + t e' e' → 𝜀 e' → 𝜀
t t→ f t' t→ f t' t→ f t'
t'
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 13: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/13.jpg)
t' → 𝛼
follow( t' ) = ‘+’, $, ‘)’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e’→ + t e' e' → 𝜀 e' → 𝜀
t t→ f t' t→ f t' t→ f t'
t' t' → 𝜀 t'→ * f t'
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 14: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/14.jpg)
t' → 𝛼
follow( t' ) = ‘+’, $, ‘)’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e'→ + t e' e' → 𝜀 e' → 𝜀
t t→ f t' t→ f t' t→ f t'
t' t' → 𝜀 t'→ * f t' t' → 𝜀
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 15: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/15.jpg)
t' → 𝛼
follow( t' ) = ‘+’, $, ‘)’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e'→ + t e' e' → 𝜀 e' → 𝜀
t t→ f t' t→ f t' t→ f t'
t' t' → 𝜀 t'→ * f t' t' → 𝜀 t' → 𝜀
f
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 16: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/16.jpg)
f → ( e )
first( ( e ) ) = ‘(’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e'→ + t e' e' → 𝜀 e' → 𝜀
t t→ f t' t→ f t' t→ f t'
t' t' → 𝜀 t'→ * f t' t' → 𝜀 t' → 𝜀
f f → ( e )
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 17: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/17.jpg)
f → x
first( x ) = ‘x’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e'→ + t e' e' → 𝜀 e' → 𝜀
t t→ f t' t→ f t' t→ f t'
t' t' → 𝜀 t'→ * f t' t' → 𝜀 t' → 𝜀
f f → x f → ( e )
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]
![Page 18: Example of Constructing a Predictive Parsing Table with an empty parsing table; the rows are non-terminals and the columns are terminals. e → t e' first( t e') = ‘(‘, ‘x’,](https://reader031.fdocuments.us/reader031/viewer/2022030413/5a9edea87f8b9a89178bfdbc/html5/thumbnails/18.jpg)
f → y
first( y ) = ‘y’
Current production:
Non-Terminal
Input Symbol
x y + * ( ) $
e e→ t e' e→ t e' e→ t e'
e' e'→ + t e' e' → 𝜀 e' → 𝜀
t t→ f t' t→ f t' t→ f t'
t' t' → 𝜀 t'→ * f t' t' → 𝜀 t' → 𝜀
f f → x f → y f → ( e )
for each production n → 𝛼for each a ∊ first(𝛼)
add n → 𝛼 to T[n , a]if 𝜀 ∊ first(𝛼) then
for each b ∊ follow(n)add n → 𝛼 to T[n , a]