资源简介
自己用python做的编译原理作业,代码有点冗余,没有完善,顺利通过老师检查
编译原理(由字母表通过运用调度场算法到逆波兰表达式到NFA到DFA到最小化DFA),python,graphiviz实现可视化

代码片段和文件信息
‘‘‘
Created on 2018年10月28日
实现NFA的Closure闭包运算及move运算以及获取NFA的列表,move列表
‘‘‘
from compilefirst.firstwork_stack import Stack
from compilefirst.firstwork_retoNFA import *
class Nfa:
def __init__(self startacceptedmove):
self.start = start
self.accepted = accepted
self.move = move
#进行闭包运算ls为状态集,u为ls状态集的闭包
def make_Closure(selfls):
u = []
ls_mid = []
stack = Stack()
for i in ls: #先把状态集全部压入栈
stack.push(i)
u.append(i)
while not(stack.is_empty()):
i = stack.pop() #取出栈顶元素
for d in self.move: #遍历状态表,如果存在空符号,则压入栈
if d.get(i) != None:
if ‘ε‘ in d.get(i):
a = d.get(i)[‘ε‘]
if a not in ls_mid and a not in u:
stack.push(a)
ls_mid.append(a)
u.append(a)
else:
pass
return u
#make_move方法求子集,ls为初态集,char为转换字符,u为转换后的集合
def make_move(selflschar):
u = []
for i in ls:
for d in self.move:
if d.get(i) != None:
if char in d.get(i):
a = d.get(i)[char]
if a not in u:
u.append(a)
# elif ‘ε‘ in d.get(i):
return u
#获得NFA的开始状态,结束状态,以及move列表
def get_startendmove(selfls):
return retoNFA(ls)
#获得NFA的字母列表
def get_alpha(selfls):
ls1 = []
for i in ls:
if i.isalpha() and i not in ls1:
ls1.append(i)
return ls1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-11-15 19:10 compilefirst\
文件 2102 2018-11-12 10:24 compilefirst\ClosureAndMove.py
文件 333 2018-11-12 18:01 compilefirst\DFA.gv
文件 12622 2018-11-12 18:01 compilefirst\DFA.gv.pdf
文件 10005 2018-11-10 10:24 compilefirst\DFAtoMDFA.py
文件 1587 2018-11-10 13:00 compilefirst\Graphsum.py
文件 90 2018-11-12 18:01 compilefirst\MDFA.gv
文件 11064 2018-11-12 18:01 compilefirst\MDFA.gv.pdf
文件 697 2018-11-12 18:01 compilefirst\NFA.gv
文件 16177 2018-11-12 18:01 compilefirst\NFA.gv.pdf
文件 3418 2018-11-12 10:23 compilefirst\NFAtoDFA.py
文件 0 2018-10-27 09:51 compilefirst\__init__.py
目录 0 2018-11-15 19:10 compilefirst\__pycache__\
文件 1704 2018-11-12 12:47 compilefirst\__pycache__\ClosureAndMove.cpython-37.pyc
文件 5046 2018-11-10 10:27 compilefirst\__pycache__\DFAtoMDFA.cpython-37.pyc
文件 1571 2018-11-10 13:00 compilefirst\__pycache__\Graphsum.cpython-37.pyc
文件 2141 2018-11-12 12:47 compilefirst\__pycache__\NFAtoDFA.cpython-37.pyc
文件 144 2018-11-08 17:52 compilefirst\__pycache__\__init__.cpython-37.pyc
文件 552 2018-11-08 17:52 compilefirst\__pycache__\firstwork_priority.cpython-37.pyc
文件 1629 2018-11-08 17:52 compilefirst\__pycache__\firstwork_re.cpython-37.pyc
文件 3514 2018-11-08 17:52 compilefirst\__pycache__\firstwork_retoNFA.cpython-37.pyc
文件 1228 2018-11-08 17:52 compilefirst\__pycache__\firstwork_stack.cpython-37.pyc
文件 603 2018-11-10 11:12 compilefirst\__pycache__\graphviz.cpython-37.pyc
文件 1725 2018-11-12 18:01 compilefirst\firstwork_main.py
文件 489 2018-10-27 15:01 compilefirst\firstwork_priority.py
文件 2573 2018-10-29 15:57 compilefirst\firstwork_re.py
文件 4166 2018-10-30 19:45 compilefirst\firstwork_retoNFA.py
文件 691 2018-10-28 13:00 compilefirst\firstwork_stack.py
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论