简体   繁体   中英

Context free grammar for CFL

enter code here Hallo, this is my question

Give context free grammar for CFL L = {a^nb^mc^n | m, n ∈ N0} L = {a^nb^mc^n | m, n ∈ N0}

My answer is S-> ASC| B A-> aA| a B-> bB| b C-> cC| c S-> ASC| B A-> aA| a B-> bB| b C-> cC| c

Whether my answer or not ? I am not sure about it. Need some help. thanks in advance

Your grammar generates the language

L = {a^n b^m c^k | m, n, k ∈ N0}

because the numbers of times that the rules A->aA and C->cC are applied are independent. If you want n=k, then you have to generate the a and c in the same rule. For example like this:

S -> aSc | B .

In a second phase you generate an arbitrary number of b in the middle:

B -> bB | <empty string> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM