[Math] Can a regular grammar be ambiguous

automatacontext-free-grammarregular-language

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?

Best Answer

There do indeed exist ambiguous regular grammars. Take for example

$S\rightarrow A~|~B$

$A\rightarrow a$

$B\rightarrow a$

Related Question