0

I have this grammar below and trying to figure out if can be parsed using the LL parser? If not, please explain.

S --> ab | cB
A --> b | Bb
B --> aAb | cC
C --> cA | Aba

From what I understand the intersection of the two sets must be empty to pass the pairwise disjointness test.

But I am not sure where to begin and have been looking through my textbook and http://en.wikipedia.org/wiki/LL_parser#Parsing_procedure but can't quite understand or find any examples to follow along. I just need to see the procedure or steps to understand how to do other similar problems to this. Any help is appreciated.

1 Answers1

1

Compute FIRST sets for all the non-terminals, and check to see if FIRST sets for the alternatives of a given non-terminal are all disjoint. If all are, it is LL, and if there are any non-terminals for which they are not it is not. If there are any ε rules, you'll need FOLLOW sets as well.

Computing FIRST1 sets is quite easy and will tell you if the grammar is LL(1). Computing FIRSTk sets is quite a bit more involved, but will tell you if the grammar is LL(k) for any specific k you calculate the FIRSTk sets for.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
  • So would the first set for B is {a,c} and C is {c,b,a} and A is {b,a,c}. Am i doing this correct? so now what would S be? – Jessica Dinh Oct 22 '14 at 06:06
  • @JessicaDinh yes, it looks like you computed the FIRST sets for A,B, and C correctly. And because they are not disjoint the grammar is not LL1 parsable. Now you can continue to generate the FIRST sets for larger Ks until you find a suitable K or give up. Did you have to determine if the grammar was LL(1) or LL(K) for any K? – Mike Dinescu Oct 22 '14 at 17:23