简体   繁体   English

DFA和正则表达式

[英]DFA and Regular Expression

A program should not write to a connection handle while the handle is in "closed" state. 句柄处于“关闭”状态时,程序不应写入连接句柄。 At the beginning, a connection will be in "connected" state, but it can move to the "error" state when "disconnect" event is followed by "write". 一开始,连接将处于“已连接”状态,但是当“断开连接”事件后接着“写入”时,它可以移至“错误”状态。 A "reconnect" event moves connection back into "connected" state, in which "write" operations are allowed. “重新连接”事件将连接移回“已连接”状态,其中允许“写入”操作。 Multiple disconnects, reconnect and writes are redundant which means second consecutive operation has no effect. 多次断开连接,重新连接和写入是多余的,这意味着第二次连续操作无效。

Model it as a regular expression and DFA? 将其建模为正则表达式和DFA?

I thought of DFA as 4 states: connect, disconnect, write, error and three possible moves from them (connect, write and disconnect) but no idea of regular expression. 我将DFA视为4种状态:连接,断开连接,写入,错误以及从中进行的三种可能的移动(连接,写入和断开连接),但不知道正则表达式。

I read it slightly differently, with three states: 我对它的阅读略有不同,具有三种状态:

  1. Open 打开
  2. Closed 关闭
  3. Error 错误

and three characters/transitions 和三个字符/过渡

  1. write
  2. disconnect 断开
  3. reconnect 重新连接

With a DFA of 使用DFA DFA

Here I've assumed that we can't leave the socket open, so only closed is an acceptance state 在这里,我假设我们不能让套接字保持打开状态,所以只有closed是接受状态

We can ignore error (There's no way out of the error state because we want to fail those strings) 我们可以忽略error (没有办法退出error状态,因为我们要使这些字符串失败)

Assuming we start in the open state, need to accept any number of write and reconnect transitions, then one or more disconnect transitions to disconnect 假设我们从open状态开始,需要接受任意数量的writereconnect转换,然后一个或多个disconnect转换来断开连接

[wr]*d+

But we can also reconnect from the disconnected state. 但是我们也可以从断开状态重新连接。 Note that the above accepts r as the first character. 请注意,上面接受r作为第一个字符。 Our final regular expression is 我们最后的正则表达式是

([wr]*d+)+

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

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