An ambiguous grammar is a context-free grammar for which there exists a string that has more than one leftmost derivation, while an unambiguous grammar is a context-free grammar for which every valid string has a unique leftmost derivation.
A regular grammar is a mathematical object, $G$, with four components, $G = (N, \Sigma, P, S)$, where
- $N$ is a nonempty, finite set of nonterminal symbols,
- $\Sigma$ is a finite set of terminal symbols, or alphabet, symbols,
- $P$ is a set of grammar rules, each of one having one of the forms:
- $A \rightarrow aB$
- $A \rightarrow a$
- $A \rightarrow \varepsilon$ for $A, B \in N$, $a \in Σ$, and $\varepsilon$ the empty string, and
- $S ∈ N$ is the start symbol.
Now the question is: Can a regular grammar also be ambiguous?
Every regular grammar which contains a rule of the form $A \rightarrow aB$ (reachable from the start symbol) has an equivalent ambiguous regular grammar. Just take a new non-terminal symbol, $D$, add the rule $A \rightarrow aD$, and for each rule with $B$ as the left symbol add a new rule obtained by replacing each $B$ in that rule with $D$.
For example, the following regular grammar is unambiguous:
$$\begin{align} S &\rightarrow aS \mid bA \\ A &\rightarrow bA \mid aB \mid \varepsilon \\ B &\rightarrow aB \mid \varepsilon \end{align}$$
Taking the rule $A \rightarrow aB$ we construct an equivalent ambiguous regular grammar as follows: $$\begin{align} S &\rightarrow aS \mid bA \\ A &\rightarrow bA \mid aB \mid aD \mid \varepsilon \\ B &\rightarrow aB \mid \varepsilon \\ D &\rightarrow aD \mid \varepsilon \end{align}$$
Then the string $ba$ has the following two leftmost derivations: