LL(2) language that is not LL(1)
Asked Answered
H

3

16

In order to further my understanding of parsers and grammars, I'm searching for a (hopefully simple) example of a language that is LL(2) but not LL(1). That is, a language that can be generated by an LL(2) grammar but not by any LL(1) grammar.

Are there useful languages in that class ? I.e could we imagine a computer language that is LL(2) but not LL(1) ?

Herbage answered 17/5, 2012 at 10:42 Comment(2)
dl.acm.org/citation.cfm?id=805431 (see the abstract)Zilpah
Thanks, but this is not what I asked. I know that such languages exist. I just want to see one of them as an example.Herbage
P
10

Parsing Techniques by Grune and Jacobs presents an example. An older version of this book is available online at

http://dickgrune.com/Books/PTAPG_1st_Edition/BookBody.pdf

and the example is on page 181.

Pieeyed answered 17/5, 2012 at 17:47 Comment(0)
H
19

The example mentioned in the book linked in Gunther's answer:

S -> a S A | epsilon
A -> a^k b S | c

is a grammar describing an LL(k+1) language that is not LL(k). In particular,

S -> a S A | epsilon
A -> a b S | c

is a grammar describing an LL(2) language that is not LL(1).

Herbage answered 18/5, 2012 at 18:24 Comment(0)
P
10

Parsing Techniques by Grune and Jacobs presents an example. An older version of this book is available online at

http://dickgrune.com/Books/PTAPG_1st_Edition/BookBody.pdf

and the example is on page 181.

Pieeyed answered 17/5, 2012 at 17:47 Comment(0)
V
0

In the book that Gunther mentioned, there's a more trivial example:

S -> a^k b | a^k a

is a grammar describing an LL(k+1) language that is not LL(k). In particular,

S -> ab | aa

is a grammar describing an LL(2) language that is not LL(1).

Vicinage answered 28/6, 2022 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.