Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presenter: Yu Hao, Tseng Date: 2014/8/25

Similar presentations


Presentation on theme: "Presenter: Yu Hao, Tseng Date: 2014/8/25"โ€” Presentation transcript:

1 Presenter: Yu Hao, Tseng Date: 2014/8/25
2019/5/25 Glushkov NFA Presenter: Yu Hao, Tseng Date: 2014/8/25 Department of Computer Science and Information Engineering National Cheng Kung University, Taiwan R.O.C. CSIE CIAL Lab 1

2 Outline Introduction Definitions Constructing Procedure Glushkov
2019/5/25 Outline Introduction Definitions Constructing Procedure Glushkov NFA2DFA National Cheng Kung University CSIE Computer & Internet Architecture Lab CSIE CIAL Lab 2

3 Introduction We mark the positions of the characters of ฮฃ in RE, counting only characters. (AT|GA)((AG|AAA)*) => (A1T2|G3A4)((A5G6|A7A8A9)*) The Glushkov automaton is built first on the marked expression RE and it recognizes L(RE). The set of positions is taken as a reference, becoming the set of states of the resulting automaton in addition to an initial state 0. So we build m+1 states labeled from 0 to m. National Cheng Kung University CSIE Computer & Internet Architecture Lab

4 Definitions We need four new definitions to explain in depth the algorithm. ๐น๐‘–๐‘Ÿ๐‘ ๐‘ก( ๐‘…๐ธ ) ๐ฟ๐‘Ž๐‘ ๐‘ก( ๐‘…๐ธ ) ๐น๐‘œ๐‘™๐‘™๐‘œ๐‘ค( ๐‘…๐ธ , ๐‘ฅ) ๐ธ๐‘š๐‘๐‘ก๐‘ฆ ๐‘…๐ธ National Cheng Kung University CSIE Computer & Internet Architecture Lab

5 Definitions (Cont.) ๐น๐‘–๐‘Ÿ๐‘ ๐‘ก( ๐‘…๐ธ ) = {๐‘ฅโˆˆ๐‘ƒ๐‘œ๐‘  ๐‘…๐ธ , โˆƒ๐‘ขโˆˆ ฮฃ โˆ— , ๐‘Ž ๐‘ฅ ๐‘ขโˆˆ๐ฟ( ๐‘…๐ธ )}
๐น๐‘–๐‘Ÿ๐‘ ๐‘ก( ๐‘…๐ธ ) = {๐‘ฅโˆˆ๐‘ƒ๐‘œ๐‘  ๐‘…๐ธ , โˆƒ๐‘ขโˆˆ ฮฃ โˆ— , ๐‘Ž ๐‘ฅ ๐‘ขโˆˆ๐ฟ( ๐‘…๐ธ )} Ex : First((A1T2|G3A4)((A5G6|A7A8A9)*)) = {1, 3} ๐ฟ๐‘Ž๐‘ ๐‘ก( ๐‘…๐ธ ) = {๐‘ฅโˆˆ๐‘ƒ๐‘œ๐‘  ๐‘…๐ธ , โˆƒ๐‘ขโˆˆ ฮฃ โˆ— , ๐‘ข ๐‘Ž ๐‘ฅ โˆˆ๐ฟ( ๐‘…๐ธ )} Ex : Last((A1T2|G3A4)((A5G6|A7A8A9)*)) = {2, 4, 6, 9} ๐น๐‘œ๐‘™๐‘™๐‘œ๐‘ค( ๐‘…๐ธ , ๐‘ฅ) = {๐‘ฆโˆˆ๐‘ƒ๐‘œ๐‘  ๐‘…๐ธ , โˆƒ๐‘ข,๐‘ฃโˆˆ ฮฃ โˆ— , ๐‘ข ๐‘Ž ๐‘ฅ ๐‘Ž ๐‘ฆ ๐‘ฃโˆˆ๐ฟ( ๐‘…๐ธ )} Ex : ๐น๐‘œ๐‘™๐‘™๐‘œ๐‘ค((A1T2|G3A4)((A5G6|A7A8A9)*), 6) = {7, 5} ๐ธ๐‘š๐‘๐‘ก๐‘ฆ ๐‘…๐ธ ๐ธ๐‘š๐‘๐‘ก๐‘ฆ ๐œ€ = ๐œ€ , ๐ธ๐‘š๐‘๐‘ก๐‘ฆ ๐›ผโˆˆฮฃ = ๐œ™ , ๐ธ๐‘š๐‘๐‘ก๐‘ฆ ๐‘…๐ธโˆ— = ๐œ€ ๐ธ๐‘š๐‘๐‘ก๐‘ฆ ๐‘…๐ธ1|๐‘…๐ธ2 = ๐ธ๐‘š๐‘๐‘ก๐‘ฆ ๐‘…๐ธ1 โˆช ๐ธ๐‘š๐‘๐‘ก๐‘ฆ ๐‘…๐ธ2 ๐ธ๐‘š๐‘๐‘ก๐‘ฆ ๐‘…๐ธ1โˆ™๐‘…๐ธ2 = ๐ธ๐‘š๐‘๐‘ก๐‘ฆ ๐‘…๐ธ1 โˆฉ ๐ธ๐‘š๐‘๐‘ก๐‘ฆ ๐‘…๐ธ2 National Cheng Kung University CSIE Computer & Internet Architecture Lab

6 Glushkov_variables (v, lpos)
If v = โ€˜|โ€™(vl, vr) OR v = โ€˜๏ผŽโ€™(vl, vr) Then lpos <= Glushkov_variables (vl, lpos) lpos <= Glushkov_variables (vr, lpos) Else If v = โ€˜*โ€™(v*) Then lpos <= Glushkov_variables (v*, lpos) If v = โ€˜ฮตโ€™ Then First(v) <= โˆ…, Last(v) <= โˆ…, Emptyv <= {ฮต} Else If v = โ€˜๐›ผโ€™, ๐›ผ โˆˆ ฮฃ Then lpos <= lpos + 1 First(v) <= {lpos}, Last(v) <= {lpos}, Emptyv <= โˆ…, Follow(lpos) <= โˆ… Else If v = โ€˜|โ€™(vl, vr) Then First(v) <= First(vl) โˆช First(vr) Last(v) <= Last (vl) โˆช Last (vr) Emptyv <= Emptyvlโˆช Emptyvr Else If v = โ€˜๏ผŽโ€™(vl, vr) Then First(v) <= First(vl) โˆช (Emptyvl ๏ผŽFirst(vr)) Last(v) <= (Emptyvr๏ผŽLast (vl)) โˆช Last (vr) Emptyv <= Emptyvl โˆฉ Emptyvr For x โˆˆ Last (vl) Do Follow(x) <= Follow(x) โˆช First(vr) Else If v = โ€˜*โ€™(v*) Then First(v) <= First(v*) Last(v) <= Last (v*) Emptyv <= {ฮต} For x โˆˆ Last (v*) Do Follow(x) <= Follow(x) โˆช First(v*) Return lpos National Cheng Kung University CSIE Computer & Internet Architecture Lab

7 Constructing Procedure โ€“ Glushkov
2019/5/25 Constructing Procedure โ€“ Glushkov Convert the parse tree into NFA using Glushkov algorithmใ€‚Ex : (AB|AD)(CE|CF)*ใ€‚ โ€˜โ€งโ€™ C B C E 1 2 5 6 โ€˜|โ€™ โ€˜*โ€™ C E Glushkov algorithm ไธป่ฆ็š„็ฒพ็ฅžๆ˜ฏๆŠŠไธ€ๅ€‹่ค‡้›œ็š„ regex ๆ‹†่งฃๆˆๆ•ธๅ€‹่ผƒๅฐไธ”่ผƒ็ฐกๅ–ฎ็š„ regex ่ฝ‰ๆˆ NFA ๅ†ๅฐ‡ๅ…ถๆ•ธๅ€‹ๅฐ NFA ไพ็…ง้€ฃๆŽฅ้‹็ฎ—็ฌฆ่™Ÿ็ต„ๅˆ่ตทไพ† Glushkov NFA ๅ› ็‚บ่ฝ‰ๆ›้Ž็จ‹่‡ดไฝฟไป–ๆœ€ๅคš State ๆ•ธ็‚บ single character ๆ•ธ้‡ + 1๏ผŒ้€™ๅ€‹ 1 ๅ› ็‚บๆ˜ฏ่ฆๅ…ˆ create an initial state A B C C . โ€˜โ€งโ€™ โ€˜โ€งโ€™ โ€˜|โ€™ C A D C C F 3 4 7 8 D C F A B A D โ€˜โ€งโ€™ โ€˜โ€งโ€™ C C E C F National Cheng Kung University CSIE Computer & Internet Architecture Lab CSIE CIAL Lab

8 Constructing Procedure โ€“ NFA2DFA
Convert NFA into DFA using subset construction algorithm [^AC] C B C E A 1 2 5 6 B [^AC] A C A C C A B 0,2 2' C A E 0, 6 5' . A [BC] [^A] B 0' 0,1,3 1' 0,5,7 4' C A C D [CEF] C 0,4 3' C F 6' 0, 8 3 4 7 8 D C F A C [^AC] A [BCD] C Symbol: A B C D E F [^AC] (a) NFA (b) DFA Subset: {0, 8} {0, 6} {0, 4} {0, 2} {0, 5, 7} {0} {0, 1, 3} National Cheng Kung University CSIE Computer & Internet Architecture Lab


Download ppt "Presenter: Yu Hao, Tseng Date: 2014/8/25"

Similar presentations


Ads by Google