8

There are two important theorems about LR(k) grammars and DCFL. Mentioned here.

  1. A language has an LR(1) grammar iff it is DCFL.
  2. A language has an LR(0) grammar iff it is DCFL and has prefix property.

I have counter example for 2nd theorem, plz see if it is valid counterexample. (Ofcourse its not valid and I am wrong, But what wrong I am doing here ?)

DCFL without prefix property: $\{b(ab)^n \mid n\geq0\}$

2nd theorem says it should not have $LR(0)$ grammar, but here it is-

$ S \rightarrow Sab \\S \rightarrow b$

PS: This is my first question here, sorry if I violated any protocol.

user3699192
  • 187
  • 2
  • 17

2 Answers2

3

Your grammar is $\mathrm{LR}(0)$ by adding a $\mathrm{\$}$ symbol to the alphabet and a starting deduction rule $S'\rightarrow S\$$ when constructing the $\mathrm{LR}(0)$ automaton (and it is a standard construction).

Omitting syntactical purposes, every DCFL $\mathrm{L}$ can be parsed by an $\mathrm{LR}(0)$ grammar for $\mathrm{L}\$$. What makes $\mathrm{LR}(k)$ ($k>0$) more practical is that it may include more syntactical information which is very important in compiler design. Otherwise, all these techniques would never be used in practice. In that case, $\mathrm{LL}(k)$ with local manipulation for expressions would be used instead, even with prohibitive cost of time and space.

Thinh D. Nguyen
  • 2,313
  • 3
  • 24
  • 71
0

As an conceptual understanding we can think of it as the grammars which satisfies prefix property can be reduced without even using look ahead as those can be accepted by DPDA which accepts through empty stack, but if language is not satisfying the prefix property we will have to check whether the look ahead is $ or any character, if its $ then we can reduce it otherwise we will have to scan input further. DPDA(empty stack acceptance) is less powerful than DPDA(final state acceptance), thats why LR(0) is less powerful than LR(1) Hope this helps.