chapter 3 regular languages
play

Chapter 3: Regular Languages In this chapter, we study: regular - PowerPoint PPT Presentation

Chapter 3: Regular Languages In this chapter, we study: regular expressions and languages; five kinds of finite automata; algorithms for processing and converting between regular expressions and finite automata; and applications of


  1. Chapter 3: Regular Languages In this chapter, we study: • regular expressions and languages; • five kinds of finite automata; • algorithms for processing and converting between regular expressions and finite automata; and • applications of regular expressions and finite automata to hardware design, searching in text files and lexical analysis. 1 / 29

  2. 3.1: Regular Expressions and Languages In this section, we: • define several operations on languages; • say what regular expressions are, what they mean, and what regular languages are; and • begin to show how regular expressions can be processed by Forlan. 2 / 29

  3. Language Operations If L 1 and L 2 are languages, then: • L 1 ∪ L 2 is a language; • L 1 ∩ L 2 is a language; • L 1 − L 2 is a language. E.g., consider union. If L 1 and L 2 are languages, then L 1 ⊆ Σ ∗ 1 and L 2 ⊆ Σ ∗ 2 , for some alphabets Σ 1 and Σ 2 . Thus is an alphabet, and L 1 ∪ L 2 ⊆ ( ) ∗ . 3 / 29

  4. Language Operations If L 1 and L 2 are languages, then: • L 1 ∪ L 2 is a language; • L 1 ∩ L 2 is a language; • L 1 − L 2 is a language. E.g., consider union. If L 1 and L 2 are languages, then L 1 ⊆ Σ ∗ 1 and L 2 ⊆ Σ ∗ 2 , for some alphabets Σ 1 and Σ 2 . Thus Σ 1 ∪ Σ 2 is an alphabet, and L 1 ∪ L 2 ⊆ (Σ 1 ∪ Σ 2 ) ∗ . 3 / 29

  5. Language Concatenation The concatenation of languages L 1 and L 2 ( L 1 @ L 2 ) is the language { x 1 @ x 2 | x 1 ∈ L 1 and x 2 ∈ L 2 } . For example, { 01 , 10 } @ { % , 11 } = = 4 / 29

  6. Language Concatenation The concatenation of languages L 1 and L 2 ( L 1 @ L 2 ) is the language { x 1 @ x 2 | x 1 ∈ L 1 and x 2 ∈ L 2 } . For example, { 01 , 10 } @ { % , 11 } = { (01)% , (10)% , (01)(11) , (10)(11) } = 4 / 29

  7. Language Concatenation The concatenation of languages L 1 and L 2 ( L 1 @ L 2 ) is the language { x 1 @ x 2 | x 1 ∈ L 1 and x 2 ∈ L 2 } . For example, { 01 , 10 } @ { % , 11 } = { (01)% , (10)% , (01)(11) , (10)(11) } = { 01 , 10 , 0111 , 1011 } . 4 / 29

  8. Language Concatenation (Cont.) Concatenation of languages is associative: for all L 1 , L 2 , L 3 ∈ Lan , ( L 1 @ L 2 ) @ L 3 = L 1 @ ( L 2 @ L 3 ) . 5 / 29

  9. Language Concatenation (Cont.) Concatenation of languages is associative: for all L 1 , L 2 , L 3 ∈ Lan , ( L 1 @ L 2 ) @ L 3 = L 1 @ ( L 2 @ L 3 ) . is the identity for concatenation: for all L ∈ Lan , And, @ L = L @ = L . 5 / 29

  10. Language Concatenation (Cont.) Concatenation of languages is associative: for all L 1 , L 2 , L 3 ∈ Lan , ( L 1 @ L 2 ) @ L 3 = L 1 @ ( L 2 @ L 3 ) . And, { % } is the identity for concatenation: for all L ∈ Lan , { % } @ L = L @ { % } = L . 5 / 29

  11. Language Concatenation (Cont.) Concatenation of languages is associative: for all L 1 , L 2 , L 3 ∈ Lan , ( L 1 @ L 2 ) @ L 3 = L 1 @ ( L 2 @ L 3 ) . And, { % } is the identity for concatenation: for all L ∈ Lan , { % } @ L = L @ { % } = L . Furthermore, ∅ is the zero for concatenation: for all L ∈ Lan , ∅ @ L = L @ ∅ = . 5 / 29

  12. Language Concatenation (Cont.) Concatenation of languages is associative: for all L 1 , L 2 , L 3 ∈ Lan , ( L 1 @ L 2 ) @ L 3 = L 1 @ ( L 2 @ L 3 ) . And, { % } is the identity for concatenation: for all L ∈ Lan , { % } @ L = L @ { % } = L . Furthermore, ∅ is the zero for concatenation: for all L ∈ Lan , ∅ @ L = L @ ∅ = ∅ . 5 / 29

  13. Language Concatenation (Cont.) Concatenation of languages is associative: for all L 1 , L 2 , L 3 ∈ Lan , ( L 1 @ L 2 ) @ L 3 = L 1 @ ( L 2 @ L 3 ) . And, { % } is the identity for concatenation: for all L ∈ Lan , { % } @ L = L @ { % } = L . Furthermore, ∅ is the zero for concatenation: for all L ∈ Lan , ∅ @ L = L @ ∅ = ∅ . We often abbreviate L 1 @ L 2 to L 1 L 2 . 5 / 29

  14. Raising a Language to a Power We define the language L n ∈ Lan formed by raising a language L to the power n ∈ N by recursion on n : L 0 = , for all L ∈ Lan ; L n +1 = LL n , for all L ∈ Lan and n ∈ N . We assign this operation higher precedence than concatenation, so that LL n means L ( L n ) in the above definition. 6 / 29

  15. Raising a Language to a Power We define the language L n ∈ Lan formed by raising a language L to the power n ∈ N by recursion on n : L 0 = { % } , for all L ∈ Lan ; L n +1 = LL n , for all L ∈ Lan and n ∈ N . We assign this operation higher precedence than concatenation, so that LL n means L ( L n ) in the above definition. 6 / 29

  16. Raising a Language to a Power (Cont.) Proposition 3.1.1 For all L ∈ Lan and n , m ∈ N , L n + m = L n L m . Proof. An easy mathematical induction on n . The language L and the natural number m can be fixed at the beginning of the proof. ✷ Thus, if L ∈ Lan and n ∈ N , then L n +1 = LL n ( definition ) , and L n +1 = L n L 1 = L n L ( Proposition 3.1.1 ) . 7 / 29

  17. Kleene Closure The Kleene closure (or just closure ) of a language L ( L ∗ ) is the language { L n | n ∈ N } . � 8 / 29

  18. Kleene Closure The Kleene closure (or just closure ) of a language L ( L ∗ ) is the language { L n | n ∈ N } . � Thus, for all w , w ∈ A , for some A ∈ { L n | n ∈ N } w ∈ L ∗ iff w ∈ L n for some n ∈ N . iff 8 / 29

  19. Kleene Closure The Kleene closure (or just closure ) of a language L ( L ∗ ) is the language { L n | n ∈ N } . � Thus, for all w , w ∈ A , for some A ∈ { L n | n ∈ N } w ∈ L ∗ iff w ∈ L n for some n ∈ N . iff For example, { a , ba } ∗ = { a , ba } 0 ∪ { a , ba } 1 ∪ { a , ba } 2 ∪ · · · = 8 / 29

  20. Kleene Closure The Kleene closure (or just closure ) of a language L ( L ∗ ) is the language { L n | n ∈ N } . � Thus, for all w , w ∈ A , for some A ∈ { L n | n ∈ N } w ∈ L ∗ iff w ∈ L n for some n ∈ N . iff For example, { a , ba } ∗ = { a , ba } 0 ∪ { a , ba } 1 ∪ { a , ba } 2 ∪ · · · = { % } ∪ 8 / 29

  21. Kleene Closure The Kleene closure (or just closure ) of a language L ( L ∗ ) is the language { L n | n ∈ N } . � Thus, for all w , w ∈ A , for some A ∈ { L n | n ∈ N } w ∈ L ∗ iff w ∈ L n for some n ∈ N . iff For example, { a , ba } ∗ = { a , ba } 0 ∪ { a , ba } 1 ∪ { a , ba } 2 ∪ · · · = { % } ∪ { a , ba } ∪ 8 / 29

  22. Kleene Closure The Kleene closure (or just closure ) of a language L ( L ∗ ) is the language { L n | n ∈ N } . � Thus, for all w , w ∈ A , for some A ∈ { L n | n ∈ N } w ∈ L ∗ iff w ∈ L n for some n ∈ N . iff For example, { a , ba } ∗ = { a , ba } 0 ∪ { a , ba } 1 ∪ { a , ba } 2 ∪ · · · = { % } ∪ { a , ba } ∪ { aa , aba , baa , baba } ∪ · · · 8 / 29

  23. Precedences of Language Operations We assign our operations on languages relative precedences as follows: • Highest: closure (( · ) ∗ ) and raising to a power (( · ) n ); • Intermediate: concatenation (@, or just juxtapositioning); • Lowest: union ( ∪ ), intersection ( ∩ ) and difference ( − ). For example, if n ∈ N and A , B , C ∈ Lan , then A ∗ BC n ∪ B abbreviates 9 / 29

  24. Precedences of Language Operations We assign our operations on languages relative precedences as follows: • Highest: closure (( · ) ∗ ) and raising to a power (( · ) n ); • Intermediate: concatenation (@, or just juxtapositioning); • Lowest: union ( ∪ ), intersection ( ∩ ) and difference ( − ). For example, if n ∈ N and A , B , C ∈ Lan , then A ∗ BC n ∪ B abbreviates (( A ∗ ) B ( C n )) ∪ B . 9 / 29

  25. Precedences of Language Operations We assign our operations on languages relative precedences as follows: • Highest: closure (( · ) ∗ ) and raising to a power (( · ) n ); • Intermediate: concatenation (@, or just juxtapositioning); • Lowest: union ( ∪ ), intersection ( ∩ ) and difference ( − ). For example, if n ∈ N and A , B , C ∈ Lan , then A ∗ BC n ∪ B abbreviates (( A ∗ ) B ( C n )) ∪ B . Can (( A ∪ B ) C ) ∗ be abbreviated? 9 / 29

  26. Precedences of Language Operations We assign our operations on languages relative precedences as follows: • Highest: closure (( · ) ∗ ) and raising to a power (( · ) n ); • Intermediate: concatenation (@, or just juxtapositioning); • Lowest: union ( ∪ ), intersection ( ∩ ) and difference ( − ). For example, if n ∈ N and A , B , C ∈ Lan , then A ∗ BC n ∪ B abbreviates (( A ∗ ) B ( C n )) ∪ B . Can (( A ∪ B ) C ) ∗ be abbreviated? No—removing either pair of parentheses will change its meaning. 9 / 29

  27. More Operations on Sets of Strings in Forlan In Section 2.3, we introduced the Forlan module StrSet , which defines various functions for processing finite sets of strings, i.e., finite languages. This module also defines the functions val concat : str set * str set -> str set val power : str set * int -> str set which implement our concatenation and exponentiation operations on finite languages. 10 / 29

  28. More Operations in Forlan (Cont.) Here are some examples of how these functions can be used: - val xs = StrSet.fromString "ab, cd"; val xs = - : str set - val ys = StrSet.fromString "uv, wx"; val ys = - : str set - StrSet.output("", StrSet.concat(xs, ys)); abuv, abwx, cduv, cdwx val it = () : unit - StrSet.output("", StrSet.power(xs, 0)); % val it = () : unit - StrSet.output("", StrSet.power(xs, 1)); ab, cd val it = () : unit - StrSet.output("", StrSet.power(xs, 3)); ababab, ababcd, abcdab, abcdcd, cdabab, cdabcd, cdcdab, cdcdcd val it = () : unit 11 / 29

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend