Algorithm for construction of predictive parsing table (MCA 4)
Algorithm for construction of predictive parsing table:
Input : Grammar G
Output : Parsing table M
Method :
-
For each production A → α of the grammar, do steps 2 and 3.
-
For each terminal a in FIRST(α), add A → α to M[A, a].
-
If ε is in FIRST(α), add A → α to M[A, b] for each terminal b in FOLLOW(A). If ε is in FIRST(α) and $ is in FOLLOW(A) , add A → α to M[A, $].
-
Make each undefined entry of M be error.
Example:
Consider the following grammar :
E → TE’
E’ → +TE’ | ε
T → FT’
T’ → *FT’ | ε
F → (E) | id