0

So I have a homework assignment and I've spent over 2hrs trying to find out why this grammar will not work with a LL parser:

<A> → a <B>
<A> → a b <C>
<B> → b d <D>
<C> → d <E>
<D> → m n
<E> → x y

Could someone please point me in the right direction? I know one of the ways an LL could get tripped up is if it runs into a infinite loop which I don't believe it does here.

Thanks

Sunny Patel
  • 578
  • 6
  • 9

1 Answers1

2

I presume that by LL Parser you mean LL(1) parser ( an LL Parser with lookahead of 1)

For a grammar to be parse-able by an LL(1) parser, it must be LL(1). There are a few things that a grammar must abide by to be LL(1), if it breaks one of these, it is called an LL(1) conflict.

  • FIRST/FIRST Conflict:

    For every non-terminal, each production must have a disjoint FIRST set. (The FIRST set is the set of all terminals that can begin sentences derived from the subject.)

    E.G: In your example above, the non-terminal has two productions:

    <A> -> a <B>
    <A> -> a b <C>
    

    The FIRST sets of each of the productions are as follows:

    FIRST(a <B>) = {a}
    FIRST(a b <C>) = {a}
    

    You can quite clearly see that these two sets intersect. This is a problem because in an LL parser, if a point is reached where A is on the stack, and the next symbol to be read is 'a', then the parser does not know whether to pick <A> -> a <B> or <A> -> a b <C>.

  • FIRST/FOLLOW Conflict:

    This occurs when, for a particular non-terminal A; FOLLOW(A) and FIRST(A) intersect and A is NULLABLE. This particular conflict does not arise in your example.

For more details on FIRST, FOLLOW and NULLABLE, i would

For more details on these conflicts, and for some examples, see the Wikipedia page on LL(1) Conflicts.

Sam Lanning
  • 636
  • 4
  • 8