It means that L is the language of strings w
consisting of symbols 'a'
, 'b'
' and 'c'
, where the length of the string w
equals to 3 times the number of symbol 'a'
present in the string w
.
The productions for this grammars should be such that if it add one 'a'
then it also adds two 'b'
, or two 'c'
, or one 'b'
; one 'c'
. Check below grammar:
S → ^ | SaSMSM | SMSaSM | SMSMSa
M → b | c
here ^
means epsilon.
To generate aabbcc
use Right most derivation
- S → SaSMSM
- replace first S in rhs by ^ using S → ^
S → SaSMSM → aSMSM - replace S → SaSMSM
S → SaSMSM → aSaSMSMMSM - use S → ^
S → SaSMSM → aSaSMSMMSM → aaSMSMMSM - use S → ^
S → SaSMSM → aSaSMSMMSM → aaSMSMMSM → aaMSMMSM - M → b
S → SaSMSM → aSaSMSMMSM → aaSMSMMSM → aaMSMMSM → aabSMMSM - use S → ^
S → SaSMSM → aSaSMSMMSM → aaSMSMMSM → aaMSMMSM → aabSMMSM → aabMMSM - M → b
S → SaSMSM → aSaSMSMMSM → aaSMSMMSM → aaMSMMSM → aabSMMSM → aabMMSM → aabbMSM - M → c
S → SaSMSM → aSaSMSMMSM → aaSMSMMSM → aaMSMMSM → aabSMMSM → aabMMSM → aabbMSM → aabbcSM - use S → ^
S → SaSMSM → aSaSMSMMSM → aaSMSMMSM → aaMSMMSM → aabSMMSM → aabMMSM → aabbMSM → aabbcSM → aabbcM - M → c
S → SaSMSM → aSaSMSMMSM → aaSMSMMSM → aaMSMMSM → aabSMMSM → aabMMSM → aabbMSM → aabbcSM → aabbcM → aabbcc