简体   繁体   English

从正则表达式不了解有限自动机中的空字符串

[英]Do not understand empty string in finite automata from regular expression

I am reading my textbook ("Introduction to the theory of computation" by Michael Sipser) and there is a part that is trying to convert the regular expression (ab U b)* into a non-deterministic finite automata. 我正在阅读我的教科书(Michael Sipser的“计算理论导论”),其中一部分试图将正则表达式(ab U b)*转换为不确定的有限自动机。 The book is telling me to break the expression apart and write a NFA for each piece. 这本书告诉我将表达式分开,并为每篇写一个NFA。 When it reaches ab it shows: 到达ab时显示:

  1. An a to go from the first state to the second 一个a从第一状态进入第二
  2. An empty string to go from the second state to the third 从第二个状态到第三个状态的空字符串
  3. A b to go from the third state to the final accepting state. a b从第三状态变为最终接受状态。

I am really confused trying to understand the second step. 试图理解第二步,我真的很困惑。 What's the purpose of the empty string. 空字符串的目的是什么。 Would it be incorrect if it wasn't there? 如果不存在会不正确吗?

You're probably making reference to example 1.56, right? 您可能正在参考示例1.56,对吗? First of all, remember he is describing a process - think of it as an algorithm, that will be executed always in the same matter. 首先,请记住他正在描述一个过程-将其视为一种算法,将始终在同一件事上执行。 What he's saying is that, if you have a regexp concatenation as PQ, no matter what P and Q are, you can join their AFNs by connecting the ending states of P with an empty string to the starting state of Q. 他的意思是,如果您将正则表达式串联为PQ,则无论P和Q是什么,都可以通过将P的结束状态与空字符串连接到Q的开始状态来加入其AFN。

So, in his example, he's creating an AFN to represent ab AFNs to represent a and b isolated are trivial, as: 因此,在他的示例中,他正在创建一个AFN来表示ab AFNs来表示a和b,这些都是琐碎的,如下所示:

->o-a->O

->o-b->O

So, in order to join both, you just follow the algorithm, putting an empty string connection from the final state of the first AFN to the starting state of the second algorithm, as: 因此,为了同时加入两者,您只需遵循算法,将一个空字符串连接从第一个AFN的最终状态到第二个算法的起始状态,如下所示:

->o-a->o-E->o-b->O

In this particular case, since it's very easy to create a ab AFD, we look at it and perceive this empty string is not necessary. 在这种特殊情况下,由于创建ab AFD非常容易,因此我们对其进行查看,并认为此空字符串不是必需的。 But the process works with every single concatenation - and, in fact, being self evident that this is equivalent of a trivially correct AFD just reinforces his statement: the process works. 但是该过程适用于每个单独的连接-实际上,很明显,这等同于简单正确的AFD只是在强化他的说法:该过程有效。

Hope that helps. 希望能有所帮助。

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

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