The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+15 votes
716 views

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.
asked in Compiler Design by Veteran (52k points)
edited by | 716 views

2 Answers

+24 votes
Best answer

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

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

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

LL(1) Parsing Table :

  $a$ $($  $)$  $+$  $*$

$\$$

$E$ $E \rightarrow aA$ $E \rightarrow (E)$        
$A$     $A \rightarrow \epsilon$ $A \rightarrow +E$ $A \rightarrow *E$  $A \rightarrow \epsilon$

 

$$\begin{array}{|l|l|l|l|l|l|l|} \hline \textbf{} & \textbf{a} & \textbf{(} & \textbf{)} & \textbf{+} & \textbf{*} & \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}$$

               

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

Follow(E)= ),\$    and  Follow(A) = ),\$
answered by Loyal (8.1k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,535 questions
54,117 answers
187,307 comments
71,028 users