edited by
292 views
2 votes
2 votes

Consider the grammar given below:

  • $S \rightarrow ABA$
  • $A \rightarrow Bc \mid dA \mid \epsilon $
  • $B \rightarrow eA$

Let $a,b,c$ and $\$$ be indexed as follows:
$$\begin{array}{|c|c|c|c|c|} \hline
c & d & e & \$
\\\hline
2 & 3 & 5 & 7
\\\hline
\end{array}$$
If $\alpha$ is the index values for the symbols in the FOLLOW set of the non-terminal $A$, $\beta$ is the index values for the symbols in the FOLLOW set of the non-terminal $B$ and $\gamma$ is the index values for the symbols in the FOLLOW set of the non-terminal $S$, all in their ascending orders, the value of $\alpha - \beta + \gamma =$ _______

(For example, if the FOLLOW set is $(c,d,e,\$)$ , then the answer should be $2357$)

edited by

1 Answer

Best answer
2 votes
2 votes

Given that the grammar:

  • $S \rightarrow ABA$
  • $A \rightarrow Bc \mid dA \mid \epsilon $
  • $B \rightarrow eA$

Now, we can calculate the FIRST and FOLLOW sets:

  • $FIRST(S) = \{d,e\}$
  • $FIRST(A) = \{d,e,\epsilon\}$
  • $FIRST(B) = \{e\}$
  • $FOLLOW(S) = \{\$\}$
  • $FOLLOW(A) = \{\$,c,d,e\}$
  • $FOLLOW(B) = \{\$,c,d,e\}$

$\textbf{For A:}$ Follow set in ascending order:

$$\begin{array}{|c|c|c|c|c|} \hline
 c & d & e & \$ \\\hline
 2 & 3 & 5 & 7 \\\hline
\end{array}$$

$\therefore \alpha = 2357$

$\textbf{For B:}$ Follow set in ascending order:
$$\begin{array}{|c|c|c|c|c|} \hline
 c & d & e & \$ \\\hline
 2 & 3 & 5 & 7 \\\hline
\end{array}$$

$\therefore \beta = 2357$

$\textbf{For S:}$ Follow set in ascending order:
$$\begin{array}{|c|c|c|c|c|} \hline
  \$ \\\hline
  7 \\\hline
\end{array}$$
$\therefore \gamma = 7$

Now, $\alpha - \beta + \gamma =  7.$

So, the correct answer is $7.$

selected by
Answer:

Related questions

1 votes
1 votes
1 answer
1
gatecse asked Dec 14, 2020
108 views
The attribute of three arithmetic operators in some programming language are given below.$$\begin{array}{|c|c|c|c|}\hline \textbf{OPERATOR} & \textbf{PRECEDENCE} & \textb...
2 votes
2 votes
1 answer
2
gatecse asked Dec 14, 2020
195 views
Consider the following grammar:$S \rightarrow abS \mid acS \mid c $The number of states in canonical set of $LR(0)$ items is ________
6 votes
6 votes
1 answer
4