0% found this document useful (0 votes)
105 views

Example of Constructing A Predictive Parsing Table

The document describes the process of constructing a predictive parsing table for a given grammar. It begins with an empty parsing table and populates the cells by considering each production rule and adding the rule to cells corresponding to the first set of the rule's right side or the follow set of the left side if epsilon is a possibility. The example walks through populating the table cell-by-cell for each production until the table is fully constructed.

Uploaded by

Aditya Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views

Example of Constructing A Predictive Parsing Table

The document describes the process of constructing a predictive parsing table for a given grammar. It begins with an empty parsing table and populates the cells by considering each production rule and adding the rule to cells corresponding to the first set of the rule's right side or the follow set of the left side if epsilon is a possibility. The example walks through populating the table cell-by-cell for each production until the table is fully constructed.

Uploaded by

Aditya Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Example of Constructing a

Predictive Parsing Table

Grammar:
e
e'

t
t'

|
|

first and follow sets:


t e'
+ t e'

NonTerminal

first

follow

(, x, y

$, )

e'

+,

$, )

(, x, y

+, $, )

f t'
* f t'

t'

*,

+, $, )

(, x, y

*, +, ), $

(e)
x
y

Start with an empty parsing table; the rows are


non-terminals and the columns are terminals.
NonTerminal
e
e'
t
t'
f

Input Symbol
x

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]

NonTerminal
e
e'
t
t'
f

Current production:
e

t e'

first( t e' ) = (, x, y

Input Symbol
x

(
e t 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]

NonTerminal

e t e'

e'
t
t'
f

Current production:
e

t e'

first( t e' ) = (, x, y

Input Symbol
y

(
e t 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]

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'

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]

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'

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]

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'

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]

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'

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]

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'

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]

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'

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]

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'

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]

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'

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]

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'

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]

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'

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]

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)

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]

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)

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]

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)

You might also like