Download presentation
Presentation is loading. Please wait.
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.