-1

I know:

A language is said to be LL(1) if it can be generated by a LL(1) grammar. It can be shown that LL(1) grammars are

not ambiguous and
not left-recursive.

but i ran into a problem.

Why the Grammar

S-> aBDb

B -> lambda

D-> dD | lambda

why this grammar is not LL(1) nor SLR nor LALR? anyone could describe me?

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • 1
    no need to worry - that grammar is LL(1) and SLR(1). Who told you that is not? – Gunther Sep 02 '14 at 15:36
  • Dear @Gunther, this is a Test on P.hd Entrance exam. the answer key says this is not. –  Sep 02 '14 at 19:18
  • Another user suggests that this question has a typo in it that makes the grammar LL(1), SLR(1), and LALR(1). With the typo removed, the grammar is not LL(1), SLR(1), or LALR(1). However, I think it's probably best if that's posted as a different question, since otherwise I have to completely redo my answer from scratch. – templatetypedef Nov 09 '14 at 18:36

1 Answers1

0

This grammar is indeed LL(1). Here's the parse table:

      a     b     d       $
S     aBDb
B           eps   eps
D           eps   dD

It's also SLR(1). Here are the FOLLOW sets:

S: $
B: d, b
D: b

Here are the configurating sets:

 S' -> .S$ 
 S  -> .aBDb  ($)

 S' -> S.$

 S  -> a.BDb   ($)
 B  -> .       (b, d)

 S  -> aB.Db   ($)
 D  -> .       (b)
 D  -> .dD     (b)

 D  -> d.D     (b)
 D  -> .dD     (b)
 D  -> .       (b)

 D  -> dD.     (b)

There are no shift/reduce or reduce/reduce conflicts, so this grammar is SLR(1). Therefore, it's also LALR(1).

Hope this helps!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • Dear templatetypede, would you please send your email address? –  Sep 10 '14 at 08:02
  • your answer is completely wrong, it's not LALR and nor SLR. –  Nov 09 '14 at 13:43
  • @user153695 It's possible that I've made a mistake here, but I don't see what it is. Can you point out what error I've made? I'd like this answer to be helpful to future readers. – templatetypedef Nov 09 '14 at 18:17
  • @user153695 My apologies - I found my mistake. I left a production out of one of the SLR states. Answer updated! – templatetypedef Nov 09 '14 at 18:25
  • i sure that this is not LL(1) nor SLR nor LALR, would u agree with me ? –  Nov 09 '14 at 18:26
  • is there any on-line tools to check this grammar is LL(1)? –  Nov 09 '14 at 18:33
  • @user153695 Wait a minute - you changed the grammar in the question a few hours ago, which invalidated my answer. That's not okay - how do you know for sure that there's a typo in the original grammar? Please post that as a separate question; I'm rolling this back to the question that I answered. – templatetypedef Nov 09 '14 at 18:34
  • no, i see this question as an exam. this is exactly the same. from the comment by that user that it's not LR nor SLR nor LALR, we know there is a typo. please correct it. ! –  Nov 09 '14 at 18:54
  • @user153695 That would entirely change the answer to the question and require me to go back and update what I have here. Instead, why don't you ask a follow-up question with the right grammar? That way, there will be answers both to the correct version of the question and to this interesting but incorrect version of the question. (Also, is it really ethical to post exam questions here?) – templatetypedef Nov 09 '14 at 18:56
  • i'm sorry, after the change i post a comment, but i think edit it here. i'm sorry if i do something wrong. –  Nov 09 '14 at 18:57
  • Dear templatetypedef, i have another question on one another of your answer, can i ask? –  Nov 09 '14 at 19:21