Is it right to find the right grammar by building DFA?

This is my homework.

Exercise 3: Find the correct grammar for the language L = { a ^ nb ^ m| n + m is an odd number}. Show how you get it.

Ask a question, how can I get an answer. So here is my explanation.

Build DFA From DFA, we got S → aA | bA A → aS | bS | null Therefore, the regular grammar is G = {V, T, S, P}, where V = {S, A} - T = {a, b} - P = {S → aA | bA, A → aS | bS | null}
DFA





However, the following question:

Build a DFA that accepts the grammar-generated language in Exercise 3. Simplify the built-in DFA, if possible.

, , DFA 3. , DFA. , .

.

+4
2

DFA , grammar. , , , DFA, . DFA, , DFA .

, DFA : DFA a^n b^m, n+m odd. , , a b : ababa.

:

  S  -> 'a' L2
     -> 'b' B2

  L1 -> 'a' L2
     -> 'b' B2

  L2 -> 'a' L1
     -> 'b' B1

  B1 -> 'b' B2

  B2 -> \empty
     -> 'b' B1
  • S .
  • L1 a, b.
  • L2 a, b.
  • B1 b.
  • B2 b.

DFA.

+1

DFA - . , DFA, ​​ .

, DFA . - :

state    s    state'
------   -    ------
even_a   a    odd_a
even_a   b    odd_b
odd_a    a    even_a
odd_a    b    even_b
even_b   a    dead
even_b   b    odd_b
odd_b    a    dead
odd_b    b    even_b
dead     a    dead
dead     b    dead

. , "odd_a" "odd_b" .

0

Source: https://habr.com/ru/post/1614475/