regular expressions res
play

Regular Expressions (REs) Regular Expressions (REs) p.1/37 - PowerPoint PPT Presentation

Regular Expressions (REs) Regular Expressions (REs) p.1/37 Expressions In arithmetic: Regular Expressions (REs) p.2/37 Expressions In arithmetic: 1. expressions are constructed from numbers and variables using arithmetic


  1. ✂ � ✁ � ✂ � ✁ � ✄ ✆ ✄ ☎ ✁ ✂ � ✄ ✄ ✂ � ✂ � ✂ � � ☎ � ✂ Precedence relation Denoting the rule describing the order of ops in the evaluation of arithmetic and regular expressions we have: ✁ ✂✁ Arithmetic expressions: Regular expressions: ✁ ✁� Note: denotes expressions enclosed in parentheses Regular Expressions (REs) – p.7/37

  2. � � � Formal definitions Consider an alphabet. A regular expression (RE) over is defi ned recursivelyby the rules: Regular Expressions (REs) – p.8/37

  3. � � � Formal definitions Consider an alphabet. A regular expression (RE) over is defi ned recursivelyby the rules: Recursion basis: Regular Expressions (REs) – p.8/37

  4. ✂ ✄ � ✂ � � � ✁ ☎ ✂ � ✁ � � � Formal definitions Consider an alphabet. A regular expression (RE) over is defi ned recursivelyby the rules: Recursion basis: 1. For any , is a RE describing the language Regular Expressions (REs) – p.8/37

  5. � ✝ � ✁ ☎ ✂ ✄ � ✄ � � ✂ ✝ ✁ � ✂ ☎ ✁ � ✝ � ✂ � ✂ Formal definitions Consider an alphabet. A regular expression (RE) over is defi ned recursivelyby the rules: Recursion basis: 1. For any , is a RE describing the language 2. is a RE describing the language Regular Expressions (REs) – p.8/37

  6. ✂ ✄ ✝ � ✄ ✁ ✝ ✝ ✂ � ✁ ☎ ✂ � � � ☎ � ✄ ✂ ✁ � � � ✂ � ☎ � � � ✂ Formal definitions Consider an alphabet. A regular expression (RE) over is defi ned recursivelyby the rules: Recursion basis: 1. For any , is a RE describing the language 2. is a RE describing the language 3. is a RE describing the empty language . Regular Expressions (REs) – p.8/37

  7. � ☎ ☎ ✂ � ✂ � � ✄ � ✄ � Formal definitions, continutation Recursion body: If and are REs evaluating to the � ✁� languages and then: Regular Expressions (REs) – p.9/37

  8. � � ✂ ✂ ✂ � ✁ ✁ � � � ✂ ☎ ✂ � � ✄ ✁ ☎ � � � ✄ ✂ ✁ ✂ � ✄ � ✄ Formal definitions, continutation Recursion body: If and are REs evaluating to the � ✁� languages and then: 1. is a RE evaluating to Regular Expressions (REs) – p.9/37

  9. � � ✂ ✁ ✄ � � ✁ ✂ ✁ ✄ � � ✂ ✂ � � � ✁ ✂ � ✂ ✂ ✁ ✄ � ✂ ✂ � ✂ � � ✄ � � ☎ ✁ ✄ ✄ � � ✂ ☎ ✂ ✂ � � ✂ Formal definitions, continutation Recursion body: If and are REs evaluating to the � ✁� languages and then: 1. is a RE evaluating to 2. is a RE evaluating to Regular Expressions (REs) – p.9/37

  10. ✂ � ✄ ✁ ✆ � � ✂ ✂ � ✄ ✂ ✂ � ✁ � � ✄ ✁ ✂ ✂ ✄ � ✁ ✂ ✁ � � ✄ ☎ � ✂ � ✄ � ✄ ✁ � ✂ ✁ � � ✂ ✂ ☎ � � ☎ ✂ � � ✄ ✁ ☎ � � � ✄ ✂ ✄ ✂ � ☎ ✝ � � ✁ ✁ � � ✂ ✂ ✂ � � ✄ ✂ ✁ ✁ � � ✄ ✄ ✂ ✂ � ✁ � Formal definitions, continutation Recursion body: If and are REs evaluating to the � ✁� languages and then: 1. is a RE evaluating to 2. is a RE evaluating to 3. is a RE evaluating to ✁ ✁� where and . Regular Expressions (REs) – p.9/37

  11. Note A defi nition of the form expressed by rule (4) above is called an inductive defi nition Regular Expressions (REs) – p.10/37

  12. � � ✁ Potential confusions Do not confuse the REs and ; Regular Expressions (REs) – p.11/37

  13. � � ✁ ✝ Potential confusions Do not confuse the REs and ; 1. represents the language containing just the empty string Regular Expressions (REs) – p.11/37

  14. � � ✁ ✝ � Potential confusions Do not confuse the REs and ; 1. represents the language containing just the empty string 2. is the RE that represents the the empty language Regular Expressions (REs) – p.11/37

  15. ✄ � � ☎ � � ☎ � � ✄ � � � � ✝ ✁ � Potential confusions Do not confuse the REs and ; 1. represents the language containing just the empty string 2. is the RE that represents the the empty language Note the distinction between and . is an expression and is the set of strings specifi ed by Regular Expressions (REs) – p.11/37

  16. � ✆ ✄ � ✆ Example REs 1. , Regular Expressions (REs) – p.12/37

  17. ✄ � ✁ ☎ ✂ ✆ � � ✆ � ✁ ✄ ✂ ✆ � ✄ ✆ � � Example REs 1. , contains exactly a single 1 Regular Expressions (REs) – p.12/37

  18. ✂ � ✂ ✄ � ✁ � ✁ ☎ ✂ ✆ ✄ ✂ ✆ � � ✄ ✆ ✆ � ✄ ✆ � ✆ Example REs 1. , contains exactly a single 1 2. , Regular Expressions (REs) – p.12/37

  19. ✁ ✆ ✂ ✁ ✂ ✆ ✄ ✂ ✂ � ✄ � ✂ ✆ ✄ ✂ ✆ � ✁ ☎ � � ✆ ✄ � ✆ � ✄ � � ✆ ✄ � ✆ ✂ ☎ ✁ ✂ Example REs 1. , contains exactly a single 1 2. , contains at least one 1 Regular Expressions (REs) – p.12/37

  20. ✂ ✆ ✆ ✄ � ✆ � ✄ � ✂ ✄ ✄ ✂ ✆ ✂ ☎ ✁ � ✁ � ✆ ✂ ✂ ✂ � � ✆ ✄ � ✆ ✆ ✄ � ✆ ✂ ✄ � ✆ ✂ ☎ ✁ � ✁ � ✂ Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , Regular Expressions (REs) – p.12/37

  21. ☎ � ✂ ✆ ✂ � ✁ � ✁ � ✁ ✂ � ✂ ✆ � ✆ ✄ ✂ ✆ ✁ ✄ � ✂ ✆ � � ✄ ✂ ✆ ✄ ✂ ☎ ✂ � ✆ ✄ � ✆ ✂ ✄ � � ✆ ✄ � ✆ ☎ � ✁ � ✁ � ✄ ✂ � ✂ ✆ ✄ ✂ ✆ � ✄ ✂ Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring Regular Expressions (REs) – p.12/37

  22. ✁ ✂ ✂ ☎ ✁ � � � ✂ ✂ ✄ ✂ ✆ � � ✄ ✆ ✂ ✂ ✁ � ✁ ☎ ✂ ✆ ✄ � � � ✆ ✂ � ✄ ✆ ✄ � ☎ � ✆ ✄ � ✆ ✆ ✄ � � ✆ ✄ � ✆ ✂ ✁ ✆ ✄ ✂ � ✄ ✂ ✆ ✂ ✆ � ✂ ✂ ✂ ✂ � ✁ � Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring 4. , Regular Expressions (REs) – p.12/37

  23. � ✂ � ✆ ✂ � ✄ ✂ ✆ ✄ ✄ � ✆ ✆ ✂ ☎ ✂ ✁ � ✂ ✁ ✄ ✂ ✂ ✂ � � ✂ ✂ � ✆ � ✂ � ✁ � ✁ ☎ ✂ � � ✄ � ✁ ☎ ✂ ✆ � ✄ ✆ � ✁ ✄ ✂ ✆ � ✄ ✆ � � � ✁ � ☎ ✂ ✆ ✂ ✄ ✆ ✂ ✄ � � ✆ ✂ ✄ ✆ ✂ ✁ ✂ ✆ Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring 4. , is a string of even length Regular Expressions (REs) – p.12/37

  24. ✆ � ✂ ✆ ✂ ✄ � � ✆ ✂ ✄ ✁ � ✂ ✂ ✄ � � ✆ ✂ ☎ � ✂ ✂ ✂ ✂ � ✄ ☎ ✆ ✂ ✂ � ✁ ✁ ✂ � ✄ � � ✁ � � ✂ ✆ ✆ ✁ � ✁ ☎ ✂ ✆ � ✄ � ✂ � ✄ ✆ ✆ � ✄ ✆ � � ✂ � ✆ ✁ � ✁ ☎ ✂ ✆ ✂ ✄ ✂ ✂ � ✄ ✂ ✆ ✂ ✄ ✆ ✂ ✂ Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring 4. , is a string of even length 5. , Regular Expressions (REs) – p.12/37

  25. � ☎ ✂ ✄ � � ✂ � ✁ � ✁ ✂ ✂ ✆ ✂ ✄ ✂ � ✆ ✂ � ✄ ✆ ✂ � ✂ ✁ ✂ ✂ � ✆ ✂ ✄ � ✁ � ☎ ✂ ✆ ✂ ✂ ✂ � ✄ � ✆ ✂ ✂ ✆ ✄ ✂ � ✂ � � ✁ � ✁ ☎ ✂ ✆ ✄ ✂ ✆ � � ✄ ✂ ✆ � ✄ ✆ � ✁ ✆ � ☎ � ✆ ✂ ☎ ✂ ✁ � ✁ � ✁ ✂ ✄ ✆ ✂ ✄ ✆ ✂ � ✄ � ✆ ✂ ✂ Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring 4. , is a string of even length 5. , the length of is a multiple of three Regular Expressions (REs) – p.12/37

  26. ✂ � � ☎ ✂ ✁ ✄ � � � � ✁ ✁ ✂ ☎ ✁ ✆ ✂ ✄ � � ✆ ✂ � ✂ ✂ � ✂ ✄ ✂ ✆ ✂ ✂ ✂ ✂ � ✂ ✂ � ✆ ✁ � ✁ ☎ ✆ ✂ ✂ ✂ � ✄ ✆ ✄ ✆ ✂ � ✁ ✂ � � ✁ � ✁ ☎ ✂ ✆ ✄ ✆ ✆ � � ✄ ✄ ✆ � ✄ ✆ � ✂ ✄ ✂ � ✄ � � ✆ ✂ ✂ ✂ � � ✁ ✁ ✂ ☎ ✂ ✆ ✂ ✄ ✆ ✂ � ✄ ✄ ✆ � Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring 4. , is a string of even length 5. , the length of is a multiple of three 6. , Regular Expressions (REs) – p.12/37

  27. � � ☎ ✆ ✂ ✂ ✂ � ✄ ✁ ✆ ✂ ✂ ✂ � � ✂ ✄ ✄ ✂ � ☎ � ✁ � ✁ ☎ ✂ ✁ ✁ ✂ ✂ � � ✂ ✄ � ✄ ✁ � ✁ ☎ ✆ ✂ ✂ � ✂ � ✄ � ✆ ✂ ✂ ✂ ✂ � � ✂ ✄ ✆ ✄ ✁ ✂ ✂ ✄ ✆ ✂ � ✂ ✄ � ✁ � ✁ ☎ ✆ ✄ � ✄ ✆ � � ✄ ✂ ✆ � ✄ ✆ � ✆ ✄ � ✂ � ✆ ✂ � ✄ ✁ ✆ ✂ ✄ � � ✆ � � ✂ ✄ � ✁ � ✁ ☎ ✂ ✆ ✂ ✄ ✆ ✂ ✄ Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring 4. , is a string of even length 5. , the length of is a multiple of three 6. , Regular Expressions (REs) – p.12/37

  28. ✂ ✂ ✂ ✂ � ✂ ✂ � � ✁ � ✁ ☎ ✆ ✂ ✂ ✂ � ✄ ✂ ✆ ✂ ✆ ✂ � � ✂ ✁ ✄ � � ✂ ✆ � ✄ ✂ ✄ � ✁ ✄ � � ✄ � ✄ � ✁ ✄ � ✂ ✄ ✄ � � ✁ � ✁ ☎ ✆ ✂ ✂ ✂ ✂ � ✄ ✄ ✁ ✁ ✁ � ✄ ✁ ✆ ✂ ✄ ✆ ✂ � ✂ ✁ � ✁ � ☎ ✆ ✂ ✆ � ✄ ✆ � � ✄ ✄ ✆ � ✄ ✆ � ✂ ✄ � ✂ ✁ ☎ ✂ ✆ ✂ ✄ � � ✆ ✂ � ✄ ✂ ✆ ✄ ✂ � � ✆ ✂ ✆ ✂ ✄ � ✁ � ✁ ☎ ✂ ✆ ☎ Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring 4. , is a string of even length 5. , the length of is a multiple of three 6. , 7. , Regular Expressions (REs) – p.12/37

  29. � ✂ ✆ ✄ ✄ � ✂ ✂ ✂ ✂ ✆ ☎ ✁ � ✁ ✁ � ✂ ✂ ✂ ☎ ✁ ✄ � ✂ ✂ ✂ ✆ ✁ ✂ ✄ ✁ � ✆ ✂ ✂ � � ✆ ✂ ✁ ✂ � � ✂ ✆ � ✄ � ✂ ✆ ✄ ✁ � ✁ ✄ ✄ ✄ � � ✄ ✁ � ✄ ✂ ✄ � ✄ ✄ ✁ � ✄ ✂ ☎ ✁ � ✆ ✂ ✄ ✆ ✂ ✁ ✂ ✆ ✄ ✂ � � ✄ � ✂ ✆ ✄ ✂ ✆ � ✁ ☎ � � ✆ ✄ � ✆ ✂ ✄ � � ✆ ✄ � ✆ ✂ ☎ ✁ ✂ ✁ ✂ � ✂ ✆ ✂ ☎ ✁ � ✁ ✄ � � � ✄ ✁ ✂ � � ✄ � � � ✁ � ✁ ✂ ☎ ✂ ✆ � ✆ ✄ ✂ ✆ ✂ ✄ � ✂ � Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring 4. , is a string of even length 5. , the length of is a multiple of three 6. , 7. , starts and ends with the same symbol Regular Expressions (REs) – p.12/37

  30. � � ✄ � ✂ ✂ ✝ � ✄ ✁ ✄ � ✁ ✄ � � ✄ ✁ � ✄ ✁ ✁ ☎ ✂ � ✁ � ✂ � ✂ ✂ ✂ ✆ ☎ ✆ ✄ � ✂ ✂ ✂ ✂ ✆ ✂ ✁ ✂ ✄ � ✂ ✆ � ✁ ✄ ✂ ✆ ✁ ✄ � ✁ ✄ ✂ ☎ ✁ � ✁ � � � ✆ ✄ ✄ � ✄ ✂ � � ✂ � ✄ ✁ ✄ ✂ ✆ ✄ ✁ � ✁ ✁ ☎ ✆ ✁ ✂ ✆ ✂ ☎ ✁ � � ✆ � ✂ ✂ ✂ ✆ � � ✄ ✂ ✂ ✂ ☎ ✁ � ✁ � � ✄ � ✂ ✆ ✄ ✂ ✆ ✆ ✄ ✄ ✆ ✆ ✂ ✆ ✂ � � ✂ ✂ ✆ � ✄ ✆ ✄ � � ✂ ✂ ✄ � � ✄ ✄ � ✂ ✆ � � ✂ ✄ ✆ ✂ ☎ ✁ � ✁ � ✂ Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring 4. , is a string of even length 5. , the length of is a multiple of three 6. , 7. , starts and ends with the same symbol 8. , Regular Expressions (REs) – p.12/37

  31. � ✄ ✂ � � ✄ ✁ � ✄ ✄ � � � ✄ ✁ � ✄ ✂ ☎ ✁ � � ✄ ✝ ✂ ✂ � ✂ ✂ ✂ ✂ ✆ ✄ ✁ ✁ ✂ ✂ ✂ ✂ ✆ ☎ ✁ � � ✄ � ✄ ✁ ✄ ✂ ✆ ✄ ✁ � ✁ ✂ ✆ ☎ ✁ � ✁ � ✂ ✝ ✂ ✁ � ✂ � ✄ ✄ ✂ ✆ � ✂ ✆ � ✁ ✂ � ✆ ✄ ✁ � ✁ ✄ ✄ ✄ � ✄ ✁ � ✆ ✆ ✄ ✂ ✆ ✁ ✄ � ✂ ✄ ✄ ✂ ✆ ✂ ☎ ✁ � ✁ � ✆ ✂ ✂ ✄ � � ✆ ✄ � ✆ ✂ ✄ � ✆ ✆ ✄ � ✆ ✂ ☎ ✁ � ✁ � ✂ ✂ � ✂ � ✄ ☎ ✂ ✂ � ✂ ✂ ✆ ✁ ✆ ✄ � ✂ ✂ ✂ ✆ ☎ ✁ � � ✆ ✂ � � ✄ ✂ ✆ � ✄ � ✆ ✁ � � ✄ ✂ ✆ ✂ ☎ ✁ � � Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring 4. , is a string of even length 5. , the length of is a multiple of three 6. , 7. , starts and ends with the same symbol 8. , Regular Expressions (REs) – p.12/37

  32. ☎ ✂ ✄ ☎ ✄ � � ✄ ✁ � ✄ ☎ ✁ ✁ � ✄ ✄ � ✄ ✂ ✂ � � ✄ ✆ ✂ ✂ ✂ ✆ ✁ ✄ � ✂ ✂ ✂ ✆ � ✆ ✁ � ✁ ✄ � � ✂ ✁ ✂ � ✂ ✝ ✂ ☎ ✁ � ✁ � ✄ ✂ ✂ � ✁ � ✁ ✝ ✂ ✄ ✆ ✁ ✄ � ✄ � ✁ ✄ ✄ ✂ ✆ ✄ ✁ � ✁ ✄ ✆ � ✁ � ✂ ✆ � ✁ ✄ ✂ ✆ ✄ ✂ � � ✂ ✄ ✂ ✆ ✄ ✄ � ✂ ✆ ✄ ✆ ✂ ✂ ☎ ✁ � ✁ � � ✂ ✂ ✆ ✁ ✆ ✆ � ✆ ✄ � ✆ ✂ ✄ � � ✄ ✂ � ✆ ✂ ☎ ✁ � ✁ � ✝ ✂ � ✄ ✂ � � ✂ ✂ ✂ ✆ ✂ ✄ � ✂ � ✂ ✆ ☎ ✁ � ✁ � ✆ ✂ ✂ ✄ � � ✄ ✂ ✆ ✝ ✄ � ✂ ✆ � ✄ � ✂ ✆ ✂ ☎ ✁ � ✁ � ✁ � � Example REs 1. , contains exactly a single 1 2. , contains at least one 1 3. , contains as a substring 4. , is a string of even length 5. , the length of is a multiple of three 6. , 7. , starts and ends with the same symbol 8. , 9. , Regular Expressions (REs) – p.12/37

  33. Regular Expressions (REs) – p.12/37 ✂ � ✁ ✄ ✄ � � ✂ ✆ � ✁ ✄ ✆ ✄ ✄ ✁ � ✁ ✄ ✂ ☎ ✁ � ✁ � ✂ ✁ ✆ � ☎ ✄ ✁ ✄ ✄ � � ✄ ✁ � ✄ ✂ ✁ ✂ � ✄ ✄ � ✄ ✂ � ✂ ✆ � ✁ ✄ � ✁ ✂ ✄ ✁ ✝ ✂ ✄ � � � ✁ ✝ ✂ � ✁ � ✝ ✂ ✂ ☎ ✁ ✝ ✄ ✄ ✄ � ✄ ✂ ✄ ✂ ✝ ✆ ✂ ✄ ✆ ✄ � � � ✁ ✝ ✂ ✄ ✂ ✝ ☎ ✁ � ✄ ✆ ✁ ✄ ✆ ✂ � � ✁ � � ✁ ✂ ✆ � � ✄ ✂ ✆ ✄ ✆ ✄ � ✆ � � � � ✄ ✂ ✆ ✂ ☎ ✁ � ✂ ✂ � ✄ � ✂ ✁ ☎ ✂ ✆ ✄ ✂ ✆ ✂ � � ✂ ✆ ✆ ✄ ✂ ✆ ✂ ☎ ✁ � ✁ � ✁ ✂ ✂ � � � ✆ ✁ ✆ � ✂ ✂ ✂ � ✆ � ✄ � ✂ ✂ ✂ ✂ ✆ ✁ ✁ ✄ ✂ � ✄ � ✂ � � ✁ ✂ ✂ ☎ ✆ � ✄ ✄ � ✂ ✂ ✂ ✆ ☎ starts and is a multiple of three as a substring contains exactly a single 1 contains at least one 1 is a string of even length contains the length of � ☎✄ ends with the same symbol Example REs , , , , , , , , , 1. 2. 3. 4. 5. 6. 7. 8. 9.

  34. ✁ ✁ ✂ ✄ ✁ ✁ ✄ � ✂ ✄ ✁ ☎ � More example 10. , ; Note: concatenating to any set yields Regular Expressions (REs) – p.13/37

  35. ✁ � � � � ☎ ✄ ✁ � ✄ � ✄ ✁ ✁ ✁ ✄ ✄ ✂ ✁ ✄ � ☎ ✁ ✁ ✂ � More example 10. , ; Note: concatenating to any set yields 11. , ; by defi nition, is in the star operation applied on any language; if the language is empty becomes the one element Regular Expressions (REs) – p.13/37

  36. � Identities If is a RE then the following identities take place: Regular Expressions (REs) – p.14/37

  37. ✁ � � ☎ � ✄ � � ✁ � ☎ � ✄ Identities If is a RE then the following identities take place: ; adding the empty language to any other language will not change that language Regular Expressions (REs) – p.14/37

  38. � � ✄ � ☎ � � � � ✄ � ☎ ☎ � � ✄ � ☎ ✁ ✁ � � ✄ � � Identities If is a RE then the following identities take place: ; adding the empty language to any other language will not change that language ; concatenating any string with the empty string does not change that string Regular Expressions (REs) – p.14/37

  39. ✄ � � ☎ � ✁ � � ✄ ✁ � � ☎ � � � � � � ✄ � � ✁ � ☎ � � ✄ � � ☎ ✁ � � Note . Example: if then ; Regular Expressions (REs) – p.15/37

  40. ✁ � � � � ✄ � � � ✁ ☎ � � ✄ � ☎ � ✁ � � � � ✄ � � ☎ � � � ✁ � ✁ � � � ✄ � � ✁ � ☎ � � ✄ � � ☎ ✁ � � � � ✄ � � ☎ � � ☎ ✄ � � ✁ � ☎ ✄ Note . Example: if then ; . Example: if then but Regular Expressions (REs) – p.15/37

  41. � Application REs are useful tools for the design of compilers Regular Expressions (REs) – p.16/37

  42. � � Application REs are useful tools for the design of compilers Language lexicon is described by REs. Regular Expressions (REs) – p.16/37

  43. ✟ ✝ ✁ � � � � ✆ ✂ � � ☎ ✁ � ✄ ✄ ✄ ✄ ✆ ✆ ✟ ✄ ✄ ✂ � ✟ ✄ ✁ ☎ ✄ ✆ ✝ ✆ ✂ � � � ✆ ✁ � � ✄ Application REs are useful tools for the design of compilers Language lexicon is described by REs. Example: numerical constants can be described by: where ✁ ☎✄ ✂ ☎✄ ☎ ☎✄ ✞ ☎✄ Regular Expressions (REs) – p.16/37

  44. � � ✁ � ✟ � � ✆ ✂ ✄ ☎ � ✁ � ✄ ✄ ✄ ✝ ✄ ✄ ✆ ✟ ✆ ✄ � � ✂ ✟ ✁ ☎ ✄ ✆ ✝ ✆ ✂ � � � ✆ ✁ � � ✄ Application REs are useful tools for the design of compilers Language lexicon is described by REs. Example: numerical constants can be described by: where ✁ ☎✄ ✂ ☎✄ ☎ ☎✄ ✞ ☎✄ From the lexicon description by REs one can generate automatically lexical analyzers Regular Expressions (REs) – p.16/37

  45. � ✄ � � ☎ ✄ � � ☎ New terminology A RE that evaluates to the language is further said that specifi es the language Regular Expressions (REs) – p.17/37

  46. � Equivalence with FA REs and fi nite automata are equivalentin their descriptive power Regular Expressions (REs) – p.18/37

  47. � � � � Equivalence with FA REs and fi nite automata are equivalentin their descriptive power Any RE can be converted into a fi nite automaton, ✁✄✂ , that recognizes the language specifi ed by Regular Expressions (REs) – p.18/37

  48. � � ✁ ✁ � � � Equivalence with FA REs and fi nite automata are equivalentin their descriptive power Any RE can be converted into a fi nite automaton, ✁✄✂ , that recognizes the language specifi ed by Vice-versa, any fi nite automaton recognizing a language can be converted into a RE that � ✁� specifi es the language Regular Expressions (REs) – p.18/37

  49. Theorem 1.54 Language is regular iff some RE specifi es it Regular Expressions (REs) – p.19/37

  50. Theorem 1.54 Language is regular iff some RE specifi es it Proof idea: this proof has two parts: Regular Expressions (REs) – p.19/37

  51. � Theorem 1.54 Language is regular iff some RE specifi es it Proof idea: this proof has two parts: First part: we show that a language specified by a RE is regular, i.e., there is a finite automaton that recognizes it. Regular Expressions (REs) – p.19/37

  52. � � Theorem 1.54 Language is regular iff some RE specifi es it Proof idea: this proof has two parts: First part: we show that a language specified by a RE is regular, i.e., there is a finite automaton that recognizes it. Second part: we show that if a language is regular then there is a RE that specifies it Regular Expressions (REs) – p.19/37

  53. Lemma 1.55 If a language is specifi ed by a RE, then it is regular. Regular Expressions (REs) – p.20/37

  54. ✁ � Lemma 1.55 If a language is specifi ed by a RE, then it is regular. Proof idea: Assume that we have a RE that evaluate to the language . Regular Expressions (REs) – p.20/37

  55. ✁ � � � Lemma 1.55 If a language is specifi ed by a RE, then it is regular. Proof idea: Assume that we have a RE that evaluate to the language . 1. We will show how to convert into an NFA that recognizes . Regular Expressions (REs) – p.20/37

  56. � ✁ � � � � Lemma 1.55 If a language is specifi ed by a RE, then it is regular. Proof idea: Assume that we have a RE that evaluate to the language . 1. We will show how to convert into an NFA that recognizes . 2. Then by corollary 1.40, if an NFA recognizes then is regular Regular Expressions (REs) – p.20/37

  57. � � Proof Convert into an NFA by the following six-steps proce- dure: Regular Expressions (REs) – p.21/37

  58. ✄ ✁ ✂ ✁ ✄ ✂ ✂ ☎ � � ☎ ✁ � � � ✄ � � ☎ � � ✄ ✂ � ✁ � � � � Step 1: If , then and the NFA recognizing is in Figure 1 Figure 1: NFA recognizing Regular Expressions (REs) – p.22/37

  59. � ✁ ✂ ✁ ✄ ✂ ✂ ☎ � ☎ ✄ ✁ � � � ✄ � � ☎ � � ✄ ✂ � ✁ � � � � Step 1: If , then and the NFA recognizing is in Figure 1 Figure 1: NFA recognizing Note: this is an NFA but not a DFA because it has states with no exiting arrow for each possible input symbol Regular Expressions (REs) – p.22/37

  60. � ✁ � � ✁ � ☎ � � � ✂ ☎ ✂ ✂ � ✁ ☎ ☎ � ✁ � ✄ � � � ✁ � � � � � ✁ � ✂ ✁ � ☎ ✁ ✂ ✁ � � ✁ � � ✂ ✁ � Formal construction � ✁� Formally where: , � ✁✄ , for and Regular Expressions (REs) – p.23/37

  61. ☎ ✁ ✝ ✁ � ✂ ✂ ☎ � � ✄ � ✁ � � � ☎ � � ✄ � � � Step 2: If then and the NFA that recognizes is in Figure 2 Figure 2: The NFA recognizing Regular Expressions (REs) – p.24/37

  62. � � ☎ ✁ ✁ ✂ ✄ ☎ ✁ ☎ ✁ ✁ � � ✁ ✂ ✁ � ✁ ✁ � � � � � ☎ Formal construction � ✁� � ✁� Formally where: � ✁✄ for any and Regular Expressions (REs) – p.25/37

  63. � ☎ ✄ ☎ ✂ ☎ ✁ � � � � ✄ � ✁ � � � Step 3: If then , and the NFA that recognizes is in Figure 3 Figure 3: he NFA recognizing Regular Expressions (REs) – p.26/37

  64. ✁ ✁ ✁ � ✂ ✁ ☎ ✄ ✁ � ✂ ☎ ✁ � ✁ ✁ ☎ � � � ☎ Formal construction � ✁� Formally where: � ✁✄ for any and Regular Expressions (REs) – p.27/37

  65. ☎ � ✁ ☎ � � ✄ � ✂ � ✄ � ☎ ✂ � ✁ � � � � ✄ Step 4: If then . � ✁� Regular Expressions (REs) – p.28/37

  66. ✄ � ✄ ✁ ☎ ✂ � ☎ � ☎ � � ✄ � ✂ � ✁ � � � � � Step 4: If then . � ✁� Note: in view with the inductive nature of we may assume that: Regular Expressions (REs) – p.28/37

  67. � � � � ✄ ✂ ✁ ☎ ✁ ☎ � ✂ ✁ ✄ ✂ ✄ ✁ ✁ ✄ ✄ ✁ ☎ � ✂ ✄ � � � � ✁ � ✂ ✂ � � � ☎ � ✄ � ✁ ☎ ✁ ✄ ✄ Step 4: If then . � ✁� Note: in view with the inductive nature of we may assume that: 1. is an NFA recognizing Regular Expressions (REs) – p.28/37

  68. ✁ � ✂ ✄ ✁ ✂ ✄ ✄ ✁ ✄ ✂ ✁ ✂ ✂ ✄ � ✁ ✁ ✂ ✄ ☎ ✂ ☎ � � ✂ ✄ ✂ ✄ ✁ ✂ ✄ ✄ � ✂ � � � � � ✁ � ✂ ✂ ✄ � � ☎ � ✄ ✂ � � ☎ ✁ ☎ ✂ ✄ � � ☎ ☎ ✂ � � ✄ ✁ ✄ Step 4: If then . � ✁� Note: in view with the inductive nature of we may assume that: 1. is an NFA recognizing 2. is an NFA recognizing Regular Expressions (REs) – p.28/37

  69. ✁ ✄ ☎ � ✂ ✁ � � ✄ ☎ ✂ � ✂ ✄ ✁ ✄ ✄ ✂ � ✁ ✂ � ✄ ✂ ✂ ✂ ✂ ✄ ✄ � ✄ ✂ ✁ ✄ ✂ ✄ ✂ ✁ ✄ ✂ ✄ � ✄ � ☎ � � ☎ ☎ ✂ � ✁ � � � � ✂ ✁ ✂ � ✄ ✁ � � ☎ ✁ ☎ � ✄ � ✁ � ☎ ✂ � � � Step 4: If then . � ✁� Note: in view with the inductive nature of we may assume that: 1. is an NFA recognizing 2. is an NFA recognizing The NFA recognizing is given in Figure 4 Regular Expressions (REs) – p.28/37

  70. ✝ ✂ � � ✄ � ☎ ✂ ✄ ✄ ✄ ✄ ✄ ✄ � ✝ ✂ ✁ ✂ ✂ ✄ ✄ ✄ ✂ ✂ ✄ ✄ ✄ ✂ ✁ ✂ ✁ ✁ NFA recognizing ✂✆☎ Figure 4: Construction of to recognize Regular Expressions (REs) – p.29/37

  71. ✂ ✁ ☎ ✂ ☎ ✄ ✄ � ✁ � ☎ ✁ ✂ ✄ ✄ ✁ ☎ � ✁ Construction procedure 1. : That is, the states of are all states on and with the addition of a new state Regular Expressions (REs) – p.30/37

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