-3

i had problem with my homework, can someone explane me for the question below. thank you

Construct a CFG for RE below :

  1. a* b* (a│c)*
  2. (a│c)* ba

1 Answers1

0

If you want to write CFG for regular expression, try to understand what regular expression is saying.

For e.g. in 1. ab(a|c)*, we are given with regular expression for any number of a's followed by any number b's followed by any number of a or c's. To write CGF for this,

S--> ABC
A--> aA | ^
B--> bB | ^
C--> aC | cC | ^

Where variable A will take care of a*, variable B will take care of b*, C will take care of (a|c)*

Similarly, for 2. (a|c)*ba, we are given with regular expression for any number of a or c followed by substring ba. CGF for this will be,

S--> Aba
A--> aA | cA | ^
Kamal Aujla
  • 327
  • 2
  • 10