160 likes | 249 Vues
LING/C SC/PSYC 438/538. Lecture 10 9/27 Sandiway Fong. Administrivia. Homework 2 graded, you should have email from me this afternoon Review Set of states construction exercise Homework Install SWI-Prolog on your machines. Review. From lecture 7 NDFSA equivalent to deterministic FSA
E N D
LING/C SC/PSYC 438/538 Lecture 10 9/27 Sandiway Fong
Administrivia • Homework 2 • graded, you should have email from me this afternoon • Review • Set of states construction exercise • Homework • Install SWI-Prolog on your machines
Review • From lecture 7 • NDFSA equivalent to deterministic FSA • Set of states construction • Exercise: • eliminate ε-transitions using the set-of-states construction • ε-transition implies non-determinism (can be in more than one state at a time)
Set-of-states construction • Converting a NDFSA into a DFSA a b > 1 2 3 a b ε {1,2} {2} {3} b
Set-of-states construction • Converting a NDFSA into a DFSA a b a b > 1 2 3 ε {1,3} {2} {3}
Regular Languages and FSA • Formal (constructive) definition of a regular language • Correspondence between REs and Regular Languages • concatenation (juxtaposition) • union (| also [ ]) • Kleene closure (*) = (x+ = xx*) • Note: • Perl backreferences are too powerful, e.g. L = {ww} and prime number testing
Regular Languages and FSA • Other closure properties: • Not true higherup: e.g. context-free grammars as we’ll see later
Equivalence: FSA and REs JM gives one direction only • Case by case: • Empty set • Any character from the alphabet • Empty string
Equivalence: FSA and REs • Concatenation: • Link final state of FSA1 to initial state of FSA2 using an empty transition Empty transition can be eliminated using set of states construction
Equivalence: FSA and REs • Kleene closure: • Repetition operator: zero or more times • use empty transitions for loop and bypass
Equivalence: FSA and REs • Union: aka disjunction • Non-deterministically run both FSAs at the same time, accept if either accepts
Regular Languages and FSA • Other closure properties: Let’s consider building the composite FSA machinery for each of these guys in turn…
Regular Expressions from FSA Textbook Exercise: find a RE for • Examples (* denotes string not in the language): • *ab*ba • bab • λ (empty string) • bb • *baba • babab
Regular Expressions from FSA • Draw a FSA and convert it to a RE: b b [Powerpoint Animation] > 1 2 3 4 b a b ε b* b ( )+ ab+ = b+(ab+)* | ε
Regular Expressions from FSA • Perl implementation: $s = "abbabab bb babababab"; while ($s =~ /\b(b+(ab+)*)\b/g) { print "<$1> match!\n"; } • Output: perltest.prl <bab> match! <bb> match! <babab> match! Note: doesn’t include the empty string case Note: /../g global flag for multiple matches (see lecture 9)
Homework • We’re going to take a detour from the textbook • when we look at Regular Grammars • the programming language Prolog has great facilities for handling phrase structure grammar rules • Install SWI-Prolog on your machines • Freely available from • http://www.SWI-Prolog.org/ • Read about Prolog on the internet • Lots of tutorials etc. available online… • http://www.swi-prolog.org/www.html