我说得对吗? (有限自动机)

发布于 2024-10-20 05:18:29 字数 447 浏览 11 评论 0原文

我得到了一个正则表达式,我应该将其转换为 NFA,然后转换为 DFA。这是正则表达式:

a ( b | c )* a | aac* b

然后我使用 Thomson 算法将其转换为 NFA: NFA

这是 DFA: DFA

有人可以快速浏览一下让我知道我是错还是对吗?

I was given a regular expression, and I am suppose to covert it to NFA and then DFA. Here's the regular expression:

a ( b | c )* a | a a c* b

Then I coverted this to NFA using Thomson's algorithm:
NFA

and here's the DFA:
DFA

Can someone please take a quick look at let me know if I am wrong or right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴随着你 2024-10-27 05:18:29

由于这很可能是家庭作业,因此我犹豫是否要给您完整的正确解决方案。

您的 NFA 看起来是正确的,但有很多不必要的多余状态,但不会对其正确性产生不利影响。 (乍一看,您似乎可以删除 11 个州。)

不过,您的 DFA 是不正确的。这是因为当您分支开始处理字符串的一个条件或另一个条件时,稍后将它们重新连接在一起。这允许它从匹配 a(b|c)*a 的接受字符串中获取路径,并通过行进获取另一个 bc到节点 15,1711。然后它接受该字符串,即使它与您的表达式不匹配。

您需要做的基本上就是阻止这种情况发生。如果您还有其他问题,请随时提问。

我强烈建议您制作一个您知道应该接受和不应该接受的测试字符串列表,然后跟踪它们,确保您的自动机以正确的(接受或拒绝)状态结束。

Since this is very likely homework, I'm hesitant to just give you the complete correct solution.

Your NFA appears correct, but has a lot of superfluous states that aren't necessary but do not adversely affect its correctness. (At first glance it looks like you could remove 11 states.)

Your DFA is incorrect, though. This is because when you branch off to begin handling one condition of the string or the other, you later rejoin them together. This allows it to take the path from an accepted string matching a(b|c)*a and take in another b or c by travelling to nodes 15,17 or 11. It then accepts this string even though it doesn't match your expression.

What you need to do is basically stop this from happening. If you have additional questions feel free to ask.

I highly recommend making a list of test strings that you know should be and shouldn't be accepted, and then trace them through, making sure your automata ends in the correct (accept or reject) state.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文