retagged by
16,441 views
25 25 votes

Consider the following statements.

  • $S_1:$ Every $\text{SLR(1)}$ grammar is unambiguous but there are certain unambiguous grammars that are not $\text{SLR(1)}$.
  • $S_2:$ For any context-free grammar, there is a parser that takes at most $O(n^3)$ time to parse a string of length $n$.

Which one of the following options is correct?

  1. $S_1$ is true and $S_2$ is false
  2. $S_1$ is false and $S_2$ is true
  3. $S_1$ is true and $S_2$ is true
  4. $S_1$ is false and $S_2$ is false

2 Answers

Best answer
41 41 votes

Correct option is C.  Both statements are correct.

An unambiguous grammar is not necessarily $\text{SLR}(1).$ But every $\text{SLR}(1)$ grammar is unambiguous.

We do have $\text{CYK}$ algorithm which takes $O(n^3)$ time (assuming size of the context-free grammar $|G|$ to be a constant) to parse any string of length $n$ using a context-free grammar $G.$

edited by
Answer:
Position:
Show:

Related questions

46 46 votes
13 13 answers
25.3k
25.3k views
Arjun asked Feb 18, 2021
25,285 views
​​​Consider the following grammar (that admits a series of declarations, followed by expressions) and the associated syntax directed translation $\text{(SDT)}$ actions, g...
25 25 votes
2 answers 2 answers
12.6k
12.6k views
Arjun asked Feb 18, 2021
12,614 views
Consider the following context-free grammar where the set of terminals is $\{a,b,c,d,f\}$. $$\begin{array}{lll} \text{S} & \rightarrow & d \: a \: \text{T} \mid \text{R} ...
32 32 votes
4 answers 4 answers
23.3k
23.3k views
Arjun asked Feb 18, 2021
23,316 views
Consider the following $C$ code segment:a = b + c; e = a + 1; d = b + c; f = d + 1; g = e + f;In a compiler, this code segment is represented internally as a directed acy...
26 26 votes
3 answers 3 answers
13.7k
13.7k views
Arjun asked Feb 18, 2021
13,704 views
Consider the following statements.$S_1:$ The sequence of procedure calls corresponds to a preorder traversal of the activation tree.$S_2:$ The sequence of procedure retur...