23 votes 23 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 $ Compute the FIRST and FOLLOW sets for $E$ and $A$. Complete the LL(1) parse table for the grammar. Compiler Design gatecse-2001 compiler-design parsing normal descriptive + – Kathleen asked Sep 14, 2014 • edited Dec 12, 2018 by Mk Utkarsh Kathleen 4.8k views answer comment Share Follow See 1 comment See all 1 1 comment reply sukesh_reddy commented Nov 22, 2022 reply Follow Share I came across a very tricky case while solving this question ie. Follow(E) contains Follow(A) because of the third production and at the same time Follow(A) contains the Follow(E) because of the first production .. how do we handle such a situation in follows of one anouther are depending .. 0 votes 0 votes Please log in or register to add a comment.
Best answer 39 votes 39 votes 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}$$ Aditya answered Aug 12, 2015 • edited Apr 17, 2019 by akash.dinkar12 Aditya comment Share Follow See 1 comment See all 1 1 comment reply Rishi yadav commented Jan 9, 2018 reply Follow Share Hello @aditya i have just structured your parsing table 3 votes 3 votes Please log in or register to add a comment.
1 votes 1 votes First(E) = a,( and First(A) = +,*,epsilon Follow(E)= ),\$ and Follow(A) = ),\$ jayendra answered Jan 2, 2015 jayendra comment Share Follow See all 2 Comments See all 2 2 Comments reply bharatmnair246 commented Dec 14, 2020 reply Follow Share how did $ come in follow of A, can somebody pls explain ?? 0 votes 0 votes Jerry J. J. commented Jun 25, 2021 reply Follow Share 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 $. 1 votes 1 votes Please log in or register to add a comment.