The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+16 votes
2k views

Consider the CFG with $\left\{S, A, B\right\}$ as the non-terminal alphabet, $\{a, b\}$ as the terminal alphabet, $S$ as the start symbol and the following set of production rules:

$S \rightarrow aB$            $S \rightarrow bA$

$B \rightarrow b$               $A \rightarrow a$ 

$B \rightarrow bS$           $A \rightarrow aS$

$B \rightarrow aBB$       $S \rightarrow bAA$

Which of the following strings is generated by the grammar?

  1. $aaaabb$
  2. $aabbbb$
  3. $aabbab$
  4. $abbbba$
asked in Compiler Design by Veteran (59.4k points)
edited by | 2k views
0
S -> aA ...from where ?
0
how did you get 3rd step from the second step??
+1
Hm. Sorry.    I did not notice bS is not present in production.
+1
Grammar(DCFL) for generating equal number of $a's$ and $b's$. Excluding $\epsilon$.
0
Just check for equal no of a's and b's .

2 Answers

+22 votes
Best answer
$S  \rightarrow aB$
    $ \rightarrow aaBB$
    $ \rightarrow aabB$
    $ \rightarrow aabbS$
    $ \rightarrow aabbaB$
    $ \rightarrow aabbab$
answered by Veteran (342k points)
edited by
+3
S->bAA ->baa

so it is not the grammer for generating equal numbers of a's and b's
+1

 SbA

A
     A  a

A
A         A aS

S

           bAA

 

how will this generate aabbab? reply quick

0
are there two grammers here?? is the string supposed to be generated by both of them??
+4
No it is one grammar having all these productions

as S->aB  s->bA, can be written as S->aB|bA

we need to find which of the given string can be derived by Grammar.

and then for that string , how many different derivations are possible
0
thanks, i was confused that how could s-> bA lead to aabbab
0 votes
ans c) b)
answered by Active (5.2k points)
0
no, you can not generate b) from given grammar if you try to generate b) you will get string "aabbbba" here one "a" at last position is extra

you can  generate c) only
Answer:


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

35,499 questions
42,767 answers
121,499 comments
42,151 users