Example of Constructing A Predictive Parsing Table
Example of Constructing A Predictive Parsing Table
Grammar:
e
e'
t
t'
|
|
NonTerminal
first
follow
(, x, y
$, )
e'
+,
$, )
(, x, y
+, $, )
f t'
* f t'
t'
*,
+, $, )
(, x, y
*, +, ), $
(e)
x
y
Input Symbol
x
NonTerminal
e
e'
t
t'
f
Current production:
e
t e'
first( t e' ) = (, x, y
Input Symbol
x
(
e t e'
NonTerminal
e t e'
e'
t
t'
f
Current production:
e
t e'
first( t e' ) = (, x, y
Input Symbol
y
(
e t e'
NonTerminal
e t e'
e t e'
e'
t
t'
f
Current production:
e
t e'
first( t e' ) = (, x, y
Input Symbol
+
(
e t e'
NonTerminal
e t e'
e t e'
e'
t
t'
f
Current production:
e'
+ t e'
first( + t e' ) = +
Input Symbol
+
(
e t e'
e' + t e'
NonTerminal
e t e'
e t e'
e'
t
t'
f
Current production:
e'
follow( e' ) = $, )
Input Symbol
+
e t e'
e' + t e'
e'
NonTerminal
e t e'
e t e'
e'
t
t'
f
Current production:
e'
follow( e' ) = $, )
Input Symbol
+
e'
e'
e t e'
e' + t e'
NonTerminal
e t e'
e t e'
e'
t
t'
f
Current production:
t
f t'
first( f t' ) = (, x, y
Input Symbol
+
e'
e'
e t e'
e' + t e'
t f t'
NonTerminal
e t e'
e t e'
t'
f
f t'
first( f t' ) = (, x, y
Input Symbol
+
t f t'
e'
e'
e t e'
e' + t e'
e'
t
Current production:
t f t'
NonTerminal
e t e'
e t e'
t'
f
f t'
first( f t' ) = (, x, y
Input Symbol
+
t f t'
t f t'
e'
e'
e t e'
e + t e'
e'
t
Current production:
t f t'
NonTerminal
e t e'
e t e'
t'
f
t'
follow( t' ) = +, $, )
Input Symbol
+
t f t'
e'
e'
e t e'
e + t e'
e'
t
Current production:
t f t'
t f t'
t'
t' * f t'
NonTerminal
e t e'
e t e'
t'
f
t'
follow( t' ) = +, $, )
Input Symbol
+
t f t'
e'
e'
e t e'
e' + t e'
e'
t
Current production:
t f t'
t f t'
t'
t' * f t'
t'
NonTerminal
e t e'
e t e'
t'
f
t'
follow( t' ) = +, $, )
Input Symbol
+
t f t'
e'
e'
t'
t'
e t e'
e' + t e'
e'
t
Current production:
t f t'
t f t'
t'
t' * f t'
NonTerminal
e t e'
e t e'
t'
f
(e)
first( ( e ) ) = (
Input Symbol
+
t f t'
e'
e'
t'
t'
e t e'
e' + t e'
e'
t
Current production:
t f t'
t f t'
t'
t' * f t'
f(e)
NonTerminal
e t e'
e t e'
first( x ) = x
t f t'
t f t'
e'
e'
t'
t'
t f t'
t'
fx
e t e'
e' + t e'
t'
f
Input Symbol
e'
t
Current production:
t' * f t'
f(e)
NonTerminal
e t e'
e t e'
first( y ) = y
t f t'
t f t'
fy
e'
e'
t'
t'
t f t'
t'
fx
e t e'
e' + t e'
t'
f
Input Symbol
e'
t
Current production:
t' * f t'
f(e)