Beruflich Dokumente
Kultur Dokumente
S → aBDh
B → cC
C → bC / ∈
D → EF
E→g/∈
F→f/∈
Answer:
First Follow
S {a} {$}
B {c} {g,f,h}
C {b,∈} {g,f,h}
D {g,f,∈} {h}
E {g,∈} { f, h }
F {f,∈} {h}
Calculate “First”
Step 1. For ‘S’ : Given S → aBDh, We know for any terminal symbol ‘x’ first(X) = {x}
accordingly we will have first(S) = {a} For the start symbol S, place $ in Follow(S).
Step 2. For ‘B’: Similarly B has terminal symbol c.
Step3. For ‘C’: For this production rule first will be {∈} ⋃ {f irst of C}
Step 4. For ‘D’ : Similarly we calculate first for D using the production rule X → Y1Y2Y3,
Calculating First(X)
a b c f g h `$
S s→aBDh
B B→cC
F F →f F →∈
Method followed to construct the table:
1. Find the FIRST and FOLLOW of the given grammar.[ we have table 1. ]
2. Create a Table where Row fields are all Non-Terminals and Column fields are all terminals
including $.
3. Productions are added into Table as entries.
The way to fill entries is as follows:
For a production X->Y,
i. if Y is not ϵ, then add production X->Y into a row of X and column of FIRST(Y).
ii. If Y is ϵ, then add production X->Y into a row of X and column of FOLLOW(X)
1- Describe:
c. Predictive parsing
Answer: A type of top-down parsing approach, which is also a type of recursive descent parsing,
[means a set of mutually recursive procedures where each procedure implements one of the
non-terminal in the grammar] that does not involve any backtracking.
● Predictive parsing identifies what production to use to replace the input string.
● It does not have backtracking.
● The predictive parser uses a look ahead pointer.
● It points to the next input symbols.
● In order to make the parser free of backtracking, it uses some constraints on the grammar.
Therefore, it will only accept grammar called LL(k) grammar.
Operator precedence can only established between the terminals of the grammar. It ignores
the non-terminal.
E iAcE|iAcEeE|a
A b
Answer: A grammar is LL(1) if it is possible to choose the next production by looking at the next
token in the input string.
The first ‘L’ in LL (1) stands for scanning the input from left to right. The second ‘L’ stands for
producing a leftmost derivation. ‘1’ stands for using one input symbol of lookahead at each step
in making parsing action decisions.
b. For every nonterminal A such that first (A) contains ∈; first (A) ⋂ follow (A) = Φ
Given grammar is
E iAcE|iAcEeE|a
A b
We can inspect as per rule (a) mentioned above this given grammar violates that.