I defined a regular grammar (FSM), which starts with $ ab$ and ends with $ ba$ the following way:

- $ S \rightarrow aS$
- $ S \rightarrow bS$
- $ S \rightarrow aT$
- $ T \rightarrow bR$
- $ R \rightarrow aQ$
- $ Q \rightarrow aQ$
- $ Q \rightarrow bQ$
- $ Q \rightarrow \epsilon$

, where $ S$ is the starting element, $ \epsilon$ is the empty (null) element and the rest are just variables.

The rules 6, 7 and 8 are there, so we can end a word. However, I am trying to rewrite my grammer but without the $ Q \rightarrow \epsilon$ . I can’t use the empty element.

Can it be done? I’m not sure how.

Thanks