0

I was trying to solve a question for practice, but I met a problem when I tried to compare the sample answer with mine. Here is the grammar before conversion:

E-> S*
S-> SD
S-> D
D-> [D]
D-> x

The start symbol is E and the other non-terminal symbols are S and D.

My answer here is :

E-> S*
S-> DS'
S'-> DS'
S'->
D-> [D]
D-> x

In the sample answer, they don't have S-> DS', and E becomes E-> DS'*. Due to the methods used in the book for removing left recursions,

A -> Aa
A -> b

=>  A -> bA'
    A' -> aA'
    A' ->

there should be a S-> DS'. I'm now getting confused about this, and maybe I just did not understand this method. Could anyone give me any hints about this? And also could you please tell me the meaning of the star symbol * here? Thanks a lot!

dajavanoob
  • 15
  • 7

1 Answers1

0

There's nothing wrong with your answer. The sample answer just simplifies the grammar after transforming it.

E -> S*
S -> DS'

Given rules for S' and D, and assuming that S and E do not occur in other productions, this part of the grammar is equivalent to

E -> DS'*

The S in the first production was simply replaced by DS', as defined in the second production that has been stripped away.

The * symbol is possibly a Kleene star. It means that S can occur any number of times (including zero). But without context, it's hard to tell, and it could also mean something else.

flyx
  • 35,506
  • 7
  • 89
  • 126
  • Without seeing the text where that example appears, it seems to be unlikely that `S*` is intended to be the Kleene star. First, it would make the grammar ambiguous (because `S` is effectively `D*`) and second because CFGs are not normally written with Kleene stars (hence the recursion in the production for `S`). It seems more likely to me that the text is using `S*` as an idiosyncratic notation for "`S` followed by the end of the input", which most of us would write "`S $`". – rici May 11 '16 at 15:52
  • That might well be. It might also mean a literal `*` character. From the information in the question, it's hard to tell. I edited the answer. – flyx May 11 '16 at 18:56