How?

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+18 votes

Consider the grammar shown below

- $S \rightarrow i E t S S’ \mid a$
- $S’ \rightarrow e S \mid \epsilon$
- $E \rightarrow b$

In the predictive parse table, $M,$ of this grammar, the entries $M[S’ , e]$ and $M[S’ , \$]$ respectively are

- $\{S’ \rightarrow e S\}$ and $\{S’ \rightarrow \epsilon\}$
- $\{S’ \rightarrow e S\}$ and $\{ \}$
- $\{S’ \rightarrow \epsilon\}$ and $\{S’ \rightarrow \epsilon\}$
- $\{S’ \rightarrow e S, S’ \rightarrow \varepsilon$} and $\{S’ \rightarrow \epsilon\}$

+35 votes

Best answer

- $\text{FIRST} (S)=\{i,a\}$
- $\text{FIRST}(S')=\{e, \epsilon\}$
- $\text{FIRST}(E)=\{b\}$
- $\text{FOLLOW}(S')=\{e,\$\}$

Only when $\text{FIRST}$ contains $\epsilon,$ we need to consider $\text{FOLLOW}$ for getting the parsing table entry.

$M[S',e]=\{S' \rightarrow eS(\text{FIRST}),S' \rightarrow \epsilon \;(\text{considering }\text{FOLLOW})\}$

$M[S',\$]=\{S \rightarrow \epsilon\}$

$a $ | $i $ | $b$ | $e $ | $t $ | $\$$ | |

$S$ | $S \rightarrow a$ | $S \rightarrow ietSS'$ | ||||

$S'$ |
$S' \rightarrow eS$ $S' \rightarrow \epsilon$ |
$S' \rightarrow \epsilon$ | ||||

$E$ | $E \rightarrow b$ |

Answer is **D**

- All categories
- General Aptitude 1.4k
- Engineering Mathematics 5.9k
- Digital Logic 2.3k
- Programming & DS 4.3k
- Algorithms 3.7k
- Theory of Computation 4.6k
- Compiler Design 1.7k
- Databases 3.4k
- CO & Architecture 2.9k
- Computer Networks 3.4k
- Non GATE 1.2k
- Others 1.3k
- Admissions 506
- Exam Queries 482
- Tier 1 Placement Questions 22
- Job Queries 64
- Projects 15

40,903 questions

47,560 answers

146,291 comments

62,306 users