• edited by
22,962 views
48 48 votes

The grammar $ S \to aSa \mid bS \mid c$ is 

  1. LL(1) but not LR(1)
  2. LR(1) but not LL(1)
  3. Both LL(1) and LR(1)
  4. Neither LL(1) nor LR(1)

2 Answers

Best answer
24 24 votes
The $\textsf{LL(1)}$ parsing table for the given grammar is:

$\begin{array}{|c|c|c|} \hline
& a&b&c \\ \hline
S& S\to aSa & S\to b & S \to c \\ \hline
\end{array}$

For any given input symbol $a,b$ or $c,$ the parser has a unique move from the start and the only state – so no conflicts.

As there is no conflict in $\text{LL(1)}$ parsing table, the given grammar is $\textsf{LL(1)}$ and since every $\textsf{LL(1)}$ is also $\textsf{LR(1)},$ the given grammar is $\textsf{LL(1)}$ as well as $\textsf{LR(1)}.$
• selected by
48 48 votes

Correct Option: C

For LL(1) take First(S). and do intersection between the result. if intersection is Phi then LL(1) else not.

Making a parsing table and checking if there are two or more entries under any terminal. If yes then neither LL(1) nor LR(1).

• edited by
Answer:
Position:
Show:

Related questions

88 88 votes
8 answers 8 answers
38.3k
38.3k views
go_editor asked Sep 30, 2014
38,286 views
The program below uses six temporary variables $a, b, c, d, e, f$.a = 1 b = 10 c = 20 d = a + b e = c + d f = c + e b = c + e e = b + f d = 5 + e return d + fAssuming tha...
37 37 votes
4 answers 4 answers
13.3k
13.3k views
go_editor asked Sep 29, 2014
13,332 views
Which languages necessarily need heap allocation in the runtime environment?Those that support recursion.Those that use dynamic scoping.Those that allow dynamic data stru...
41 41 votes
5 answers 5 answers
20.5k
20.5k views
go_editor asked Sep 29, 2014
20,528 views
Which data structure in a compiler is used for managing information about variables and their attributes?Abstract syntax treeSymbol tableSemantic stackParse table
97 97 votes
10 answers 10 answers
41.1k
41.1k views
go_editor asked Apr 21, 2016
41,120 views
A computer system has an $L1$ cache, an $L2$ cache, and a main memory unit connected as shown below. The block size in $L1$ cache is $4$ words. The block size in $L2$ cac...