0
$\begingroup$

I would like to create a deterministic finite state automaton (DFA) M=(Q, Σ, δ, q0, F) that is accepting the language generated by the following regular grammar (RG) G=(N, Σ, P, S). In short I want to convert RG to DFA.

G = ({S,A,B},{a,b},P,S)
P = { 
S -> aA | bB,
A -> aS | a,
B -> bS | b
}

I have found these rules that convert RG to a finite automaton (which might not be deterministic if I think correctly).

1. δ(B, a) = C if B → aC ∈ P
2. δ(B, a) = K if B → a ∈ P
   K ∈ F
3. δ(K, *) = emptySet 
   i.e. q0 ∈ F, if S → ε ∈ P
   I dont understand rule 3

Now I am using these rules on G this way.

A -> aS
becomes
δ(A, a)=S
according to
1st rule

A -> aS
becomes
δ(A, a)=K
according to
2nd rule

Now I already have

δ(A, a)=S
δ(A, a)=K

which means the automaton is not deterministic because

δ(A, a)={S,K}

Am I doing something wrong?

$\endgroup$
  • 1
    $\begingroup$ Rule 3 says that if you're in the final state $K$, then ignore any subsequent inputs (which is what's meant by the *). As to your last question, there's no guarantee that this construction from a regular grammar to a FA will yield a DFA. If it doesn't, then there's a well-known construction (found in every intro theory text of which I'm aware) that converts a NFA to an equivalent DFA. $\endgroup$ – Rick Decker Apr 1 '15 at 19:16
  • $\begingroup$ @RickDecker I am not sure that is correct regarding rule 3. At least, it is not my interpretation. $\endgroup$ – babou Apr 1 '15 at 23:00
  • $\begingroup$ @babou. Perhaps I should have said that from state $K$ there are no transitions available on any input. How's that? $\endgroup$ – Rick Decker Apr 2 '15 at 0:16
2
$\begingroup$

As Rick Decker said, the algorithm doesnt guarantee that the conversion from G will yieald a DFA. Therefore I should convert to a NFA and than to the DFA. The howto is here.

$\endgroup$
1
$\begingroup$

The way I interpret your rules (other than 1 and 2) is:

There is a state K, not corresponding to a non-terminal of the grammar, such that K ∈ F.

Then rule 3 means that there is no transition from state K, so that any further input when you are in state 3 results in rejection of the input string. The star * means any input, and the empty set says that any input will get you in no state, hence failure unless you have no input left.

The initial state q0 is S, and it belongs also to the set F of final states iff S → ε ∈ P

Thus the set F of final states contains either only the state K or the two states S and K.

But as you remark, this gives you in general a NFA, a non-deterministic finite automaton.

To transform it into DFA, you need to apply the so-called powerset construction, that you will find in any textbook on finite automata, and in many other places, including wikipedia.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.