next up previous
Next: Annexe 1. Up: Quiz10 Previous: Exercise 2.

Exercise 3.

Consider the following grammar G with terminals a, b, c, d and nonterminals S, A, B, C.
S $ \longmapsto$ C A
A $ \longmapsto$ a B A  |  $ \varepsilon$
B $ \longmapsto$ b B  |  C d
C $ \longmapsto$ c C  |  $ \varepsilon$
We recall the rules for the computation of the FOLLOW set of each nonterminal.

if A $\displaystyle \longmapsto$ $\displaystyle \alpha$B$\displaystyle \beta$ then $\displaystyle \mbox{{\sc FOLLOW}($B$)}$ : = $\displaystyle \mbox{{\sc FIRST}(${\beta}$)}$ $\displaystyle \setminus$ {$\displaystyle \varepsilon$$\displaystyle \cup$  $\displaystyle \mbox{{\sc FOLLOW}($B$)}$
if A $\displaystyle \longmapsto$ $\displaystyle \alpha$B then $\displaystyle \mbox{{\sc FOLLOW}($B$)}$ : = $\displaystyle \mbox{{\sc FOLLOW}($B$)}$  $\displaystyle \cup$  $\displaystyle \mbox{{\sc FOLLOW}($A$)}$
if $\displaystyle \left\{\vphantom{ \begin{array}{l} A \longmapsto {\alpha} B {\beta} \\  {\beta} \stackrel{\ast}{\Longrightarrow} {\varepsilon} \end{array} }\right.$$\displaystyle \begin{array}{l} A \longmapsto {\alpha} B {\beta} \\  {\beta} \stackrel{\ast}{\Longrightarrow} {\varepsilon} \end{array}$ then $\displaystyle \mbox{{\sc FOLLOW}($B$)}$ : = $\displaystyle \mbox{{\sc FOLLOW}($B$)}$  $\displaystyle \cup$  $\displaystyle \mbox{{\sc FOLLOW}($A$)}$
   

Recall also that if $ denotes the end-of-line symbol and if S is the start symbol of the grammar (as it is the case above) then we have $ $ \in$ FOLLOW(S). Give the parsing table of G (for the non-recursive implementation of predictive parsing).

Answer 3  
\fbox{
\begin{minipage}{13 cm}
\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\mbox{ } \...
...\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\end{minipage}}


\fbox{
\begin{minipage}{13 cm}
\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\mbox{ } \...
...\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\end{minipage}}


next up previous
Next: Annexe 1. Up: Quiz10 Previous: Exercise 2.
Marc Moreno Maza
2004-12-02