版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、2. Scanning (Lexical Analysis)PART TWOContentsPART ONE2.1 The Scanning Process 2.2 Regular Expression2.3 Finite AutomataPART TWO2.4 From Regular Expressions to DFAs Open2.4 From Regular Expression To DFAs Main PurposeThe process of constructing a scanner: Regular expressions represent a pattern, tha
2、t are used as token descriptions DFAs represent algorithms that accept strings according to a pattern described in regular expressionTranslating a regular expression into a DFA via NFA.Regular ExpressionNFADFAProgramContents From a Regular Expression to an NFA MoreFrom an NFA to a DFA More Minimizin
3、g the Number of States in a DFA More2.4.1 From a Regular Expression to an NFAThe Idea of Inductive MethodIt follows the structure of the definition of a regular expressionConstruct NFA for each basic regular expression2 NFA that is equivalent to regular expression 3 NFA that is equivalent to regular
4、 expression a,a 1 NFA that is equivalent to regular expression yxyxyxaConstruct NFA for complex regular expressions2 Break up the NFA basing on the following three operations until the arrowed line is labeled by only characters 1 The NFA for regular expression “e” ise1Xye=e1|e2e2X1e1ye2e=e1e2X1ye1e=
5、e1*yxeExample: translate (a|b)*abb into an NFAX(a|b)*abbYX (a|b)* 1a 2bb 3 YX 4 1 b 3 a 2 b a|b YX 4 1 b 3 a 2 b a b YRET2.4.2 From an NFA to a DFAGoals and Methods(1) Eliminating -transitions -closure: the set of all states reachable by -transitions from a state or statesijkmaban(a)i,jmkaabn(b)Goal
6、s and Methods(2) Eliminating multiple transitions from a state on a single input character.Keeping track of the set of states that are reachable by matching a single character0123aabc(a)01,23abc(b)Goals and MethodsBoth these processes lead us to consider sets of states instead of single state. Thus,
7、 it is not surprising that the DFA we construct has sets of states of the original NFA as its states.The Algorithm Called Subset ConstructionThe -closure of a Set of states:The -closure of a single state s is the set of states reachable by a series of zero or more -transitions, and we write this set
8、 as_closure of a state always contain the state itself a2314ExampleThe -closure of a set of states: the union of the -closure of each individual state.The Subset Construction Algorithmto obtain the start state of MConstructing a DFA M from a given NFA Maa1,2,42,3,4Examples of Subset Constructiona231
9、4S1,2,42,3,42,3,42,3,4Examples of Subset Construction4a32b18567aS1,2,63,7,4,83,4,7,85, 85,81,2,6b3,4,7,85,8aRET2.4.4 Minimizing the Number of States in a DFAWhy need Minimizing?The process of deriving a DFA algorithmically from a regular expression has the unfortunate property that the resulting DFA
10、 may be more complex than necessaryThe derived DFA for the regular expression a* and an equivalent DFAaaaan Important Result from Automata Theory for MinimizingGiven any DFA, there is an equivalent DFA containing a minimum number of states, and, that this minimum-state DFA is unique It is also possi
11、ble to directly obtain this minimum-state DFA from any given DFA. Algorithm obtaining Mini-States DFAEquivalent StatesIf s and t are two states, they are equivalent if and only if:s and t are both accepting states or both non-accepting states.For each character a, s and t have transitions on a to th
12、e equivalent statesExample of Equivalent StatesC and F are all accepting states. They have transitions on a to C and have transitions on b to E, so they are equivalent states S is a non-accepting state and C is an accepting state. They are not equivalent statesaCDBAEFSbaaaaabbbbbabAlgorithm obtainin
13、g Mini-States DFASplit the set of states into some disjoint sets, so states in one set are equivalent to each other, while any two states of different sets are distinguishable.Algorithm obtaining Mini-States DFAIt begins with the most optimistic assumption possible:createing two sets, one consisting
14、 of all the accepting states and the other consisting of all the non-accepting states. 2. Consider the transitions on each character a of the alphabet for each subset, determine whether all the states in the subset are equivalent or the subset should be split Algorithm obtaining Mini-States DFA(1) I
15、f there are two states s and t in one subset that have transitions on a that land in different sets, we say that a distinguishes the states s and t(2) The set of states under consideration must be split according to where their a-transitions landAlgorithm obtaining Mini-States DFA(3)Error transition
16、s to an error state that is non-accepting. If there are two states s and t such that s has an a-transition to another states, while t has no a-transition at all (i.e., an error transition), then a distinguishes s and t.If s and t both have no a-transition, then they cant be distinguished by aAlgorit
17、hm obtaining Mini-States DFA3. Continue this process until either all sets contain only one element (in which case, we have shown the original DFA to be minimal) or until no further splitting of sets occurs.Example: The regular expression letter(letter|digit)* 10letter23letterdigitletterdigitletterdigitThe accepting sets 1,2,3The nonaccepting sets0letterdigit1letter0Example: the regular expression (a| )b*a distinguishes state 1 from states 2 and 3, and we must
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 個(gè)人房產(chǎn)抵押借款規(guī)范合同版B版
- 雙十二數(shù)碼之路
- 農(nóng)業(yè)電商春節(jié)之道
- 2024年跨境電商物流解決方案合作合同
- 2024年版企業(yè)債務(wù)償還抵扣協(xié)議版B版
- 大巴用車合同(2篇)
- 2025年度餐廚廢棄物無害化處理與綜合利用合同3篇
- 2024年高壓開關(guān)設(shè)備安裝協(xié)議
- 專業(yè)化眼科義齒2024年加工服務(wù)協(xié)議模板版B版
- 2025年父母房產(chǎn)處置與子女就業(yè)支持協(xié)議3篇
- DZ∕T 0153-2014 物化探工程測量規(guī)范(正式版)
- 商業(yè)空間設(shè)計(jì)(高職環(huán)境藝術(shù)設(shè)計(jì)專業(yè)和室內(nèi)設(shè)計(jì)專業(yè))全套教學(xué)課件
- 廣東省廣州市名校聯(lián)盟重點(diǎn)名校2024屆中考化學(xué)全真模擬試卷含解析
- 大學(xué)校園交通安全現(xiàn)狀調(diào)查分析
- 環(huán)保安全部年度安全環(huán)保工作總結(jié)模板
- RTO工藝流程簡介
- 語文新課標(biāo)背景下單元整體教學(xué):六下第4單元大單元設(shè)計(jì)
- 旅游業(yè)務(wù)年度回顧與展望
- 醫(yī)院智慧醫(yī)療及康養(yǎng)平臺系統(tǒng)采購項(xiàng)目招投標(biāo)書范本
- 駕照體檢表完整版本
- 品質(zhì)部規(guī)劃方案
評論
0/150
提交評論