in Compiler Design edited by
2,896 views
20 votes

Consider the following grammar with terminal alphabet $\Sigma =\{a,(,),+,* \}$ and start symbol $E$. The production rules of the grammar are:

  • $ E \rightarrow aA$
  • $ E \rightarrow (E)$
  • $A \rightarrow +E$
  • $A \rightarrow *E$
  • $A \rightarrow \epsilon $
  1. Compute the FIRST and FOLLOW sets for $E$ and $A$.
  2. Complete the LL(1) parse table for the grammar.
in Compiler Design edited by
2.9k views

2 Answers

32 votes
 
Best answer

First $(E) = \{ a,( \}$

First $(A) = \{ +,*, \epsilon \}$

Follow $(E) =$ Follow $(A) =$ $\{$ $\$$ $,) \}$

LL(1) Parsing Table:

$$\begin{array}{|c|c|c|c|c|c|c|} \hline \textbf{} & \textbf{a} & \textbf{(} & \textbf{)} & \textbf{+} & \bf{*} & \textbf{\$} \\\hline \text{E} & \text{E} \rightarrow \text{aA} & \text{E} \rightarrow \text{(E)} & \text{} & \text{} & \text{} & \text{} \\\hline \text{A} & \text{}& \text{} & \text{A} \rightarrow \epsilon & \text{A} \rightarrow \text{+E} & \text{A} \rightarrow *\text{E} & \text{A} \rightarrow \epsilon \\\hline \end{array}$$

edited by

1 comment

Hello @aditya i have just structured your parsing table
3
1 vote
First(E) = a,(   and   First(A) = +,*,epsilon

Follow(E)= ),\$    and  Follow(A) = ),\$

2 Comments

how did $ come in follow of A, can somebody pls explain ??
0
because Follow of A will  contain Follow of E, due to production E->aA

And since Follow of E would contain $

(Since it is the start symbol) hence Follow of A will also contain $.
0

Related questions