資源簡介
自己用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
評論
共有 條評論