[英]How to merge two finite state automata?
Say I have two deterministic finite state automata represented by the following transition diagrams: 假设我有两个确定性有限状态自动机,由以下转换图表示:
FSA for keyword IF: IF FSA关键字IF: IF
___ ___ _
/ \ I / \ F // \\
>| 0 |----->| 1 |----->||2||
\___/ \___/ \\_//
FSA for an ID: [AZ][A-Z0-9]* FSA的ID: [AZ] [A-Z0-9] *
------------
___ | _ LET |
/ \ LET // \\<------
>| 0 |----->||1||
\___/ \\_//<------
| NUM |
------------
What algorithm may I use to combine them into a single deterministic finite state automata with three final states, represented by the following transition diagram: 我可以使用什么算法将它们组合成具有三个最终状态的单个确定性有限状态自动机,由以下转换图表示:
-----------------------
| LETTER BUT F OR NUM | --------
___ | _ _ LET v _ | LET |
/ \ I // \\ F // \\----->// \\<------
>| 0 |----->||1||----->||2|| ||3||<--------
\___/ \\_// \\_//----->\\_//<------ |
| NUM | NUM | |
| ANY LETTER OTHER THAN I ------------ |
---------------------------------------------
1: ID
2: IF (IT'S ALSO AN ID, BUT THE KEYWORD IF HAS A HIGHER PRECEDENCE)
3: ID
The textbooks usually gives the automaton C
such that L(C) = L(A) UL(B)
by applying de-morgan on it, L(C) = (L(A) C [intersection] L(B) C ) C . 教科书通常通过在其上应用去摩根来给出自动机
C
使得L(C) = L(A) UL(B)
,L(C)=(L(A) C [交叉] L(B) C ) C.
The intersection is done by building the Cartesian product automaton, and the negation is simply switching the accepting states. 交叉是通过构建笛卡尔积自动机来完成的,而否定就是简单地切换接受状态。
Building the union automaton can also be done directly: Build the Cartesian product automaton, and a final state is a state (a,b)
such that a
is a final state in the automaton of A
OR b
is a final state in the automaton of B
建立联合自动机也可以直接完成:构建笛卡尔积自动机,最终状态是状态
(a,b)
,使得a
是A
OR的自动机中的最终状态b
是自动机中的最终状态。 B
An alternative is building a Non-Deterministic Final Automaton (NFA) by simply creating a new state, and add an epsilon path for both start(A) and start(B), and use the standard algorithm for eliminating non-determinism from an automaton. 另一种方法是通过简单地创建一个新状态来构建非确定性最终自动机 (NFA),并为start(A)和start(B)添加epsilon路径,并使用标准算法消除自动机的非确定性。
The problem - this automaton will not be minimal (far from it probably). 问题 - 这个自动机不会很小(可能很远)。 You can try and use this algorithm on the resulting automaton in order to minimze it.
您可以尝试在生成的自动机上使用此算法 ,以便将其最小化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.