{"id":16654193,"url":"https://github.com/letmefly666/re2dfa","last_synced_at":"2026-03-07T17:32:59.492Z","repository":{"id":107870095,"uuid":"474888384","full_name":"LetMeFly666/Re2DFA","owner":"LetMeFly666","description":"Regular expression to DFA(Deterministic Finite State) |  正则表达式转最小化DFA","archived":false,"fork":false,"pushed_at":"2022-04-12T15:21:16.000Z","size":792,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T18:12:04.970Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://re2dfa.letmefly.xyz","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LetMeFly666.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-28T07:16:23.000Z","updated_at":"2025-03-15T03:25:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"a3ad0410-343a-4853-bcf6-fa552072bb8a","html_url":"https://github.com/LetMeFly666/Re2DFA","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/LetMeFly666/Re2DFA","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LetMeFly666%2FRe2DFA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LetMeFly666%2FRe2DFA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LetMeFly666%2FRe2DFA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LetMeFly666%2FRe2DFA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LetMeFly666","download_url":"https://codeload.github.com/LetMeFly666/Re2DFA/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LetMeFly666%2FRe2DFA/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30223377,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T17:00:40.062Z","status":"ssl_error","status_checked_at":"2026-03-07T17:00:39.026Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T09:49:00.722Z","updated_at":"2026-03-07T17:32:59.469Z","avatar_url":"https://github.com/LetMeFly666.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\n * @Author: LetMeFly\n * @Date: 2022-03-28 15:29:51\n * @LastEditors: LetMeFly\n * @LastEditTime: 2022-04-10 09:18:36\n--\u003e\n# Re2DFA\n\nRegular expression to DFA(Deterministic Finite State)\n\n项目地址：[https://github.com/LetMeFly666/Re2DFA](https://github.com/LetMeFly666/Re2DFA) \n\n**使用方法**\n\n在正则表达式输入框输入正则表达式后，点击“转换”即可。\n\n当前[字符](#Character)、[运算符](#Operator)支持范围详情请点击查看。\n\n若输入不合法等导致程序出错，DFA等栏目将会显示默认状态。详情请看[错误码](#ErrorCode)\n\n以“第一个字符为0，最后一个字符1，由0和1组成的字符串”为例：\n\n运行程序：\n\n主页：\n\n![MainPage](docs/imgs/MainPage.jpg)\n\n输入前：\n\n![BeforeInput](docs/imgs/BeforeInput.jpg)\n\n输入```0(0|1)*1```并点击```转换```：\n\nNFA：\n\n![NFA](docs/imgs/NFA.jpg)\n\nDFA：\n\n![DFA](docs/imgs/DFA.jpg)\n\n简化DFA：\n\n![DFA Simplified](docs/imgs/DFA_Simplified.jpg)\n\n**编译方法**\n\n在VS中添加QT插件，配置好QT环境后，\u003ccode\u003eF5\u003c/code\u003e编译运行即可。\n\n**例如**\n\n+ ```0(0|1)*1```\n+ ```1|(0(0|1)*1)*```\n+ ```(a|b)*ab(a*|b)```\n+ ```a((a|d)*(a|d)|ε)```\n\n## 实现目标\n\n输入正则表达式，程序绘制出对应的简化DFA\n\n## 概念\n\n+ [正则表达式](#RegularExpression)\n+ [字符](#Character)\n+ [实字符](#CharacterReal)\n+ [空字符](#CharacterEmpty)\n+ [运算符](#Operator)\n+ [选择符](#OperatorOr)\n+ [连接符](#OperatorConcatenation)\n+ [括号符](#OperatorBrackets)\n+ [重复符](#OperatorRepetition)\n+ [错误码](#ErrorCode)\n\n**@Input**\n\n| 名称       | 类型   | 描述                                           |\n| :--------- | ------ | ---------------------------------------------- |\n| 正则表达式\u003ca id=\"RegularExpression\"\u003e\u003c/a\u003e | String | 代表正则表达式的字符串，包括数个[字符](#Character)和[运算符](#Operator)。 |\n\n**字符**\n\n| 名称 | 类型 | 描述                                                         |\n| ---- | ---- | ------------------------------------------------------------ |\n| 字符\u003ca id=\"Character\"\u003e\u003c/a\u003e | Char | 代表串中要出现的字符\u003cbr/\u003e•支持**实字符**\u003ca id=\"CharacterReal\"\u003e\u003c/a\u003e```a~z```、```A~Z```、```0~9```\u003cbr/\u003e•支持**空字符**\u003ca id=\"CharacterEmpty\"\u003e\u003c/a\u003e```ε``` |\n\n**运算符**\n\n| 名称   | 类型     | 描述 |\n| ------ | -------- | ---- |\n| 运算符\u003ca id=\"Operator\"\u003e\u003c/a\u003e | Operator | 确定正则的运算规则\u003cbr/\u003e•支持\u003ca href=\"#OperatorOr\"\u003e\u003cfont color=\"black\"\u003e\u003cb\u003e选择符\u003c/b\u003e\u003c/font\u003e\u003c/a\u003e\u003ccode\u003e\u0026#124;\u003c/code\u003e\u003cbr/\u003e•支持\u003ca href=\"#OperatorConcatenation\"\u003e\u003cfont color=\"black\"\u003e\u003cb\u003e连接符\u003c/b\u003e\u003c/font\u003e\u003c/a\u003e```·```\u003cbr/\u003e•支持\u003ca href=\"#OperatorRepetition\"\u003e\u003cfont color=\"black\"\u003e\u003cb\u003e重复符\u003c/b\u003e\u003c/font\u003e\u003c/a\u003e```*```\u003cbr/\u003e•支持\u003ca href=\"#OperatorBrackets\"\u003e\u003cfont color=\"black\"\u003e\u003cb\u003e括号符\u003c/b\u003e\u003c/font\u003e\u003c/a\u003e```()``` |\n\n| 名称 | 类型 | 描述 |\n| ---- | --- | --- |\n| 选择符\u003ca id=\"OperatorOr\"\u003e\u003c/a\u003e | Operator | 若```a```和```b```代表两个正则表达式，则\u003ccode\u003ea\u0026#124;b\u003c/code\u003e代表```a或b```，即无论是```a```还是```b```都能匹配正则表达式 |\n| 连接符\u003ca id=\"OperatorConcatenation\"\u003e\u003c/a\u003e | Operator | 若```a```和```b```代表两个正则表达式，则```a·b```代表```a后b```（```·```可省略，```a·b```等价于```ab```），即若一个串能从某处分成两串，使得前串匹配```a```且后串匹配```b```，则此串能匹配```a·b``` |\n| 重复符\u003ca id=\"OperatorRepetition\"\u003e\u003c/a\u003e | Operator | 若```a```代表一个正则表达式，则```a*```代表```数个a```（个数n≥0），即若一个串能分成数个串，使得每个串都匹配```a```，则此串能匹配```a*``` |\n| 括号符\u003ca id=\"OperatorBrackets\"\u003e\u003c/a\u003e | Operator | 若```a```代表一个正则表达式，则```(a)```等价于```a```。括号符不能拆开单独使用，但括号符可以提高优先级 |\n\n**优先级** ```()``` \u003e ```*``` \u003e ```·``` \u003e ```|```\n\n**错误码**\n\n\u003ca id=\"ErrorCode\"\u003e\u003c/a\u003e为了使得用户输入错误表达式时程序不至于崩溃，程序具有了一定程度上的纠错功能。\n\n目前支持以下错误处理：\n\n| 值 | 类型 | 描述 |\n| ---- | --- | --- |\n| 0 | Int | 无误 |\n| 1 | Int | )找不到( |\n| 2 | Int | 双目运算符无法出栈两个NFA |\n| 3 | Int | 单目运算符无法出栈单个NFA |\n| 4 | Int | NFA构建完毕后栈中FNA个数不为一 |\n| 5 | Int | 出现不受支持的字符 |\n| 6 | Int | 内置文件丢失 |\n| 7 | Int | 无写文件权限 |\n\n\n\n## 实现思路\n\n输入的正则表达式 → 添加上省略的· → 转换为逆波兰表达式 → 转为NFA → 可视化显示NFA → NFA转为DFA(并可视化) -\u003e 简化DFA(并可视化)\n\n### 添加上省略的·\n\n有以下情况需要在中间添加· ：\n\n```·``` ：194\u0026#124;183\n\n```ε``` ：206\u0026#124;181\n\n程序内部用 ```.``` 代表 ```·``` ，用 ```,``` 代表 ```ε```\n\n+ ab\n+ a(\n+ )a\n+ *b\n+ *(\n\n### 逆波兰到NFA\n\n#### 构建NFA\n\n构建NFA栈，从左到右遍历逆波兰表达式：\n\n+ 遇到字母：构建基本NFA入栈\n+ 遇到运算符：出栈相应数量的NFA，构建新的NFA入栈\n\n最终栈中剩且仅剩下一个NFA记为最终的NFA\n\n#### NFA的可视化\n\n这里本来准备尝试使用GraphViz。但是放弃的原因有两点：\n\n1. C语言不好配置GraphViz的头文件等，若直接调用编译好的dots.exe则Release需要增加20多M\n\n2. GraphViz生成的图像不太好控制大小方向，且似乎没有颜色\n\n当成功让QT显示了html 且 成功用js生成mermaid图后，决定使用[此项目(https://github.com/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid)的js将程序生成的源码转成图像。\n\n在此对开源项目的开发者致敬！\n\n#### NFA转为DFA\n\n**思想：** λ（ε）合并、符号合并\n\n初态：Start的ε闭包\n\n每次：走一个Char后求闭包\n\n一个新的状态集为一个DFA\n\n#### 简化DFA\n\n**思想：** 将等价状态合并。\n\n**等价状态：** 初态在同组，经过相同的路径到达的节点也在同组。\n\n**初始分组：** 初始状态将“End节点”、“非End节点”划分为2组。\n\n**编程过程注意：** \n\n若采用```map\u003cDFA*, int\u003e```来记录每个DFA对应的组号，则迭代过程中要注意不同DFA是否为同组的问题。包括但不限于：\n\n1. 起始状态不在同组但经过相同字符能到达同组的DFA不能划分为同组\n\n2. 由组中不在终态的节点建立的节点的isEnd是false，但同组有End节点的话应修改新节点的isEnd为true。（在1.的条件下似乎不会有2.的情况出现）\n\n## Release\n\n### How To Release\n\n#### 打包QT程序所需依赖\n\n##### 1. QT所需\n\n```bat\nwindeployqt Re2DFA.exe\n```\n\n其中 ```windeployqt``` 可以直接打开```QT的命令行```来使用。或者找到自己电脑上```windeployqt.exe```的位置。例如我电脑```QT安装目录```是```F:\\OtherApps\\Program\\QT\\Apps```，安装版本是```msvc2017 x64 5.14.2```，那么我电脑上```windeployqt.exe```就在：```F:\\OtherApps\\Program\\QT\\Apps\\5.14.2\\msvc2017_64\\bin\\windeployqt.exe```\n\n```bat\n\"F:\\OtherApps\\Program\\QT\\Apps\\5.14.2\\msvc2017_64\\bin\\windeployqt.exe\" Re2DFA.exe\n```\n\n**上述操作最好在一个空的文件夹(With Re2DFA.exe included)中进行。**\n\n##### 2. VS所需\n\n然后添加VS编译出来的程序运行所需要的DLL文件，包括但可能不限于：\n\n1. MSVCP140.dll\n\n2. VCRUNTIME140.dll\n\n3. VCRUNTIME140_1.dll\n\n##### 3. html所需\n\n1. DFA_tail.html\n\n2. DFA_head.html\n\n3. initialDFA.html\n\n4. mermaid.min.js\n\n### 下载发行版\n\n#### DLL、静态文件等依赖\n\n\u003cdetails\u003e\n\u003csummary\u003eQT所需\u003c/summary\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Re2DFA/releases/download/DLLs%2CStaticFilesAndSoOn/QT.Relaies.zip\"\u003eQT.Relaies.zip\u003c/a\u003e\u003c/li\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eVS所需\u003c/summary\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Re2DFA/releases/download/DLLs%2CStaticFilesAndSoOn/Dlls.Because.of.Visual.Sutdio.zip\"\u003eDlls.Because.of.Visual.Sutdio.zip\u003c/a\u003e\u003c/li\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e静态文件\u003c/summary\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Re2DFA/releases/download/DLLs%2CStaticFilesAndSoOn/HtmlAndJs.zip\"\u003eHtmlAndJs.zip\u003c/a\u003e\u003c/li\u003e\n\u003c/details\u003e\n\n#### 发行版\n\n\u003cdetails\u003e\n\u003csummary\u003ev0.0.1-x64\u003c/summary\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Re2DFA/releases/download/v0.0.1/v0.0.1-x64-Release.zip\"\u003ev0.0.1-x64-Release.zip\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://download.fastgit.org/LetMeFly666/Re2DFA/releases/download/v0.0.1/v0.0.1-x64-Release.zip\"\u003ev0.0.1-x64-Release.zip\u003c/a\u003e镜像地址\u003c/li\u003e\n\u003cli\u003e单文件：\u003ca href=\"https://github.com/LetMeFly666/Re2DFA/releases/download/v0.0.1/Re2DFA.exe\"\u003eRe2DFA.exe\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Re2DFA/archive/refs/tags/v0.0.1.zip\"\u003eSource code (zip)\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Re2DFA/archive/refs/tags/v0.0.1.tar.gz\"\u003eSource code (tar.gz)\u003c/a\u003e\u003c/li\u003e\n\u003c/details\u003e\n\n## TODO\n\n### ForBetter\n\n+ 正则表达式与运算过多时，生成的SVG图片可能水平宽度过大，导致图片上的字体非常小\n\n+ 生成的SVG图片无法上下居中（若上下居中，则竖直高度过高时可能无法上下滑动导致内容显示不全）\n\n+ 便捷输入的各个字符按钮点击后只会将字符插入到输入框末尾，而不能插入到光标所在位置\n\n+ 便捷输入的各个字符按钮点击后不会自动聚焦到输入框，而是需要再次点击输入框才能继续按键输入\n\n+ 在缩放比例不是100%的Windows系统上，字体大小会发生变化\n\n+ 程序界面大小固定，不可放大。\n\n### BugFix\n\n```None```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletmefly666%2Fre2dfa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fletmefly666%2Fre2dfa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletmefly666%2Fre2dfa/lists"}