I know that every LL(1) is also an LR(1). But what about the relationship between LL(1) and LR(0), can a LL(1) be a LR(0) as well?
Asked
Active
Viewed 2,808 times
5
-
4This might be a better question for Computer Science SE (focused on theory) than StackOverflow (focused on practice). – Charles Duffy Jan 10 '16 at 16:23
1 Answers
7
You ask two questions, one in the title and the other in the body of the post. Neither specify whether you are asking about languages or grammars, but the basic answers are the same:
Are all LL(1) languages LR(0)?
No. A language which contains both a string and a proper prefix of that string cannot be LR(0). But many LL(1) languages have that form.
Are some LL(1) languages LR(0)?
Sure.
(The unasked question) Are any LR(0) languages not LL(1).
Yes. For example, the language
{ambnc | m≥n≥0}
is LR(0), but it has no LL(1) grammar.

rici
- 234,347
- 28
- 237
- 341
-
So by your answer I can say that .. if we do not get any duplicate entries in the LL(1) table for a grammar.. then that grammar.. although it is left factored.. can be a LR(0) (if and only if the grammar is conflict (shift/reduce) free on the LR(0) table).??? – bopia Jan 11 '16 at 09:50
-
@bopia: a grammar is LR(0) if the LR(0) table is free of conflicts. Nothing else is relevant. – rici Jan 11 '16 at 12:03
-
Could you give a LR(0) grammar for the {a^mb^n | m≥n≥0} language, please? – qznc May 31 '16 at 07:32
-
@rici I guess you meant `S -> T | a S; T -> | a T b`. This is not LR(0) according to https://mdaines.github.io/grammophone Paste ` S -> T . S -> a S . T -> . T -> a T b .` – qznc Jun 01 '16 at 08:58
-
A working example is `{a^mb^nc | m≥n≥0}` with this LR(0) grammar: `S -> c . S -> a S . S -> X . X -> T c . T -> a T b . T -> a b . ` (dots denote end of rule) – qznc Jun 01 '16 at 09:01
-
1@qznc: You're right on both counts: I did mean `S -> a S` and that grammar is not LR(0), which I really should have known because it matches the empty string and grammars with λ rules cannot be LR(0). In your correction, `X` is unnecessary; you can replace `S -> X . X -> T c .` with `S -> T c .` I corrected the original post. Thanks. – rici Jun 01 '16 at 20:05