简体   繁体   English

我如何将正则表达式转换为有限自动机?

[英]How would I convert regular expression to finite automata?

How would I change the following regular expression to finite automata? 如何将以下正则表达式更改为有限自动机?

(abUb)(bUaaa)b*b((a*b)*Ub)*

note: U means union in this case 注意:在这种情况下,U表示联合

There are five top-level concatenated components of this regex. 这个正则表达式有五个顶级连接组件。 According to the algorithm recoverable from a part of Kleene's theorem, you can make NFA-Lambdas for these, then form the concatenation by connecting final states of one to initial states of the next. 根据可以从Kleene定理的一部分中恢复的算法,你可以为这些算法制作NFA-Lambdas,然后通过将一个的最终状态连接到下一个的初始状态来形成连接。

When you see a union, that means you make two machines and combine them by making a new start state with two lambda transitions. 当你看到一个联合时,这意味着你制作两台机器并通过一个带有两个lambda转换的新启动状态来组合它们。

Kleene closure is a little more involved, but basically make the machine for the thing being repeated, then transform it by adding a new accepting start state and a loop to it from the old final states. Kleene闭包更多涉及,但基本上使机器重复,然后通过从旧的最终状态添加一个新的接受启动状态和循环来转换它。

The base case is the machine for a single letter, which is two states, initial and final, with the appropriately labelled transition. 基本情况是单个字母的机器,它是两个状态,初始和最终,具有适当标记的转换。

Work recursively from the simplest machines (innermost subexpressions) up to the whole thing, combining as necessary. 从最简单的机器(最里面的子表达式)到整个事物递归地工作,根据需要组合。 Simplify the result as much as you like, possibly converting to a minimal DFA. 尽可能简化结果,可能转换为最小DFA。

There is an application called Automatic Java Code Generator for Regular Expressions and Finite Automata, that automatically generates the NFA, DFA (including the transition table), and Java Code for a given regular expression or finite automata. 有一个名为Automatic Java Code Generator for Regular Expressions and Finite Automata的应用程序,可自动生成给定正则表达式或有限自动机的NFA,DFA(包括转换表)和Java代码。 It can be downloaded from this link: www.s-solutions.info You can always check if your solution is correct or not. 可以从以下链接下载: www.s-solutions.info您可以随时检查您的解决方案是否正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM