有穷自动机表示的语言是正规语言,二者等价。

从正规表达式构造 - NFA

Thompson 构造法

从 DFA 构造正规表达式

路径迭代法

  • 将状态集用 表达,初态为 1
  • 对所有 迭代计算 ,表示一个正规表达式,从 有一条标记为 的路径,且路径上所有点除 外不大于
      • ,若不存在从 的弧,,否则
      • ,若不存在自环,,否则
  • 迭代计算得到
  • 将所有 相加( 为终态)

Example

\usetikzlibrary{automata, positioning, arrows}
\tikzset{
	->, % makes the edges directed
	>=stealth, % makes the arrow heads bold
	node distance=2.5cm, % specifies the minimum distance between two nodes. Change if necessary.
	every state/.style={thick}, % sets the properties for each ’state’ node
	initial text=$Start$, % sets the text that appears on the start arrow
}
\begin{document}
	\begin{tikzpicture}
		\node [state, initial] (q1) {$q_1$};
		\node [state, accepting, right of = q1] (q2) {$q_2$};
		\draw (q1) edge[loop above, above] node{1} (q1)
			(q1) edge[above] node{0} (q2)
			(q2) edge[loop above, above] node{0,1} (q2);
	\end{tikzpicture}
\end{document}
有限状态自动机与正规表达式 2025-11-03 20.03.17有限状态自动机与正规表达式 2025-11-03 20.03.17

状态消去法

思路:

  • 扩展自动机的概念,允许转移弧是正规表达式
  • 消去某一中间状态时,更新每一个前驱状态到每一个后继状态转移弧
  • 对每一终态 ,消去除 外的所有状态
  • ,可得到以下自动机,对应的正规表达式可表示为
\usetikzlibrary{automata, positioning, arrows}
\tikzset{
	->, % makes the edges directed
	>=stealth, % makes the arrow heads bold
	node distance=2.5cm, % specifies the minimum distance between two nodes. Change if necessary.
	every state/.style={thick}, % sets the properties for each ’state’ node
	initial text=$Start$, % sets the text that appears on the start arrow
}
\begin{document}
	\begin{tikzpicture}
		\node [state, initial] (q0) {$q_0$};
		\node [state, accepting, right of = q0] (q) {$q$};
		\draw (q0) edge[loop above, above] node{R} (q0)
			(q0) edge[above, bend left] node{S} (q)
			(q) edge[below, bend left] node{T} (q0)
			(q) edge[loop above, above] node{U} (q);
	\end{tikzpicture}
\end{document}
  • ,可得到以下自动机,对应的正规表达式可表示为
\usetikzlibrary{automata, positioning, arrows}
\tikzset{
	->, % makes the edges directed
	>=stealth, % makes the arrow heads bold
	node distance=2.5cm, % specifies the minimum distance between two nodes. Change if necessary.
	every state/.style={thick}, % sets the properties for each ’state’ node
	initial text=$Start$, % sets the text that appears on the start arrow
}
\begin{document}
	\begin{tikzpicture}
		\node [state, initial, accepting] (q0) {$q_0$};
		\draw (q0) edge[loop above, above] node{R} (q0);
	\end{tikzpicture}
\end{document}
  • 最终的正规表达式为全部终态对应的正规表达式的并