The document provides an example of constructing a predictive parsing table for a context-free grammar. It starts with an empty parsing table and then iterates through each production rule, adding entries to the table based on the first and follow sets of the production. For each production n → α, it adds n → α to each cell T[n,a] where a is in the first set of α. If ε is in the first set, it also adds entries based on the follow set of n. The table is populated row by row as it processes each production rule.
The document provides an example of constructing a predictive parsing table for a context-free grammar. It starts with an empty parsing table and then iterates through each production rule, adding entries to the table based on the first and follow sets of the production. For each production n → α, it adds n → α to each cell T[n,a] where a is in the first set of α. If ε is in the first set, it also adds entries based on the follow set of n. The table is populated row by row as it processes each production rule.
The document provides an example of constructing a predictive parsing table for a context-free grammar. It starts with an empty parsing table and then iterates through each production rule, adding entries to the table based on the first and follow sets of the production. For each production n → α, it adds n → α to each cell T[n,a] where a is in the first set of α. If ε is in the first set, it also adds entries based on the follow set of n. The table is populated row by row as it processes each production rule.
Grammar: first and follow sets: Non- e → t e' Terminal first follow
e' → + t e' e ‘(‘, ‘x’, ‘y’ $, ‘)’
‘+’, 𝜀 𝜀 e' $, ‘)’ | t ‘(‘, ‘x’, ‘y’ ‘+’, $, ‘)’ ‘*’, 𝜀 t → f t' t' f ‘(‘, ‘x’, ‘y’ ‘+’, $, ‘)’ ‘*’, ‘+’, ‘)’, $ t' → * f t' | 𝜀 f → (e) | x | y Start with an empty parsing table; the rows are non-terminals and the columns are terminals. Non- Input Symbol Terminal x y + * ( ) $ e e' t t' f for each production n → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] e → t e' if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) first( t e' ) = ‘(‘, ‘x’, ‘y’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal x y + * ( ) $ e e→ t e' e' t t' f for each production n → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] e → t e' if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) first( t e' ) = ‘(‘, ‘x’, ‘y’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal x y + * ( ) $ e e→ t e' e→ t e' e' t t' f for each production n → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] e → t e' if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) first( t e' ) = ‘(‘, ‘x’, ‘y’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal x y + * ( ) $ e e→ t e' e→ t e' e→ t e' e' t t' f for each production n → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] e' → + t e' if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) first( + t e' ) = ‘+’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal x y + * ( ) $ e e→ t e' e→ t e' e→ t e' e' e'→ + t e' t t' f for each production n → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] e' → 𝜀 if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) follow( e' ) = $, ‘)’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal x y + * ( ) $ e e→ t e' e→ t e' e→ t e' e' e'→ + t e' e' → 𝜀 t t' f for each production n → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] e' → 𝜀 if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) follow( e' ) = $, ‘)’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal 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 → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] t → f t' if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) first( f t' ) = ‘(‘, ‘x’, ‘y’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal 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 → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] t → f t' if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) first( f t' ) = ‘(‘, ‘x’, ‘y’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal 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 → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] t → f t' if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) first( f t' ) = ‘(‘, ‘x’, ‘y’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal 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 → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] t' → 𝛼 if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) follow( t' ) = ‘+’, $, ‘)’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal 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 → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] t' → 𝛼 if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) follow( t' ) = ‘+’, $, ‘)’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal 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 → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] t' → 𝛼 if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) follow( t' ) = ‘+’, $, ‘)’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal 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 → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] f → (e) if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) first( ( e ) ) = ‘(’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal 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 → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] f → x if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) first( x ) = ‘x’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal 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 → 𝛼 Current production: for each a ∊ first(𝛼) add n → 𝛼 to T[n , a] f → y if 𝜀 ∊ first(𝛼) then for each b ∊ follow(n) first( y ) = ‘y’ add n → 𝛼 to T[n , a]
Non- Input Symbol
Terminal 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)