Considering this FSM:
Can someone explain me why the grammar is not:
- $S \rightarrow aA$
- $A \rightarrow aA \mid bB \mid \varepsilon$
- $B \rightarrow bB \mid \varepsilon$
Why does A not have a transition to $\varepsilon$?
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.
Sign up to join this communityConsidering this FSM:
Can someone explain me why the grammar is not:
Why does A not have a transition to $\varepsilon$?
Both grammars are wrong: The first does allow String $b$, which is not accepted by the NFA, the second does not allow $\epsilon$, which is accepted by the NFA.
Note that some definitions of regular grammars don't allow renaming of variables, which makes the first grammar irregular. In the same way $\varepsilon$-transitions don't extend the expressive power of NFAs, renaming variables does not extend the expressive power of regular grammars.
So if the automaton is what you want (i.e. ensure that a word which contains a $b$, contains an $a$, too), just add $S \rightarrow \varepsilon$ to your second grammar. If the first grammar is what you want ($\{a\}^*\{b\}^*$) add $S{b \atop \rightarrow }B$ to your automaton and $S \rightarrow \varepsilon\mid bB$ to the second grammar.