Chapter 3 Regular languages and grammars Section 3.1 regular expressions A regular expression is operators: Examples: 1) A variable name: 2) All even length strings: 3) All strings ending in 00 or 11: Definition: Let be an alphabet. Then 1. 2. 3. Associated with each regular expression r is a language we denote by L(r). 1. 2. 3. For regular expressions r1 and r2, 4. L(r1 + r2) = 5. L(r1• r2) = 6. L((r1)) = 7. L(r1*) = operator precedence: Examples: Assume the alphabet is = {a, b} 1) Strings that contain consecutive a’s: 2) The complement of the language in 1) 3) All strings over Σ = {a, b} in which b's occur in runs of even length. Class exercise Answer: 4) Strings in which the number of a’s is odd. Class exercise Answer: 5) #7 p. 76 What languages do (*)* and a represent? 6) Strings that contain both aa and bb Answer: Class exercise 7) Strings in which aa occurs at least twice Class exercise 8) Strings that contain both ab and ba Class Exercise Answer: 9) Strings over {a, b, c} in which the total number of b’s and c’s is three Section 3.2 Connection between Regular Expressions and Regular Languages Theorem 3.1 Let r be a regular expression. Then, an NFA that accepts L(r). Consequently, L(r) is a regular language. The NFA constructed in the proof has the following properties: 1. 2. 3. The induction proof below shows how to construct an NFA from a regular expression. Regular expression to NFA construction Basis: We first construct automata for the three basis cases: Ø, , and a Hypothesis: Induction step: Finishing the Proof Case 1: Case 2: Case 3 Example: automaton for (a + b)*ab Regular expressions for regular languages Basic idea: generalized transition graph Example: eliminate vertex q2 in the figure below. Result: Theorem 3.2: Let L be a regular language. Then there exists a regular expression r such that L = L(r). Proof: Finishing the proof Example 3.11 on page 84. EE OE EE OO OE OO EE OE OO OO OE EE Thus we have: Finishing the Example Now, we need to remove OO EE OO EE EO OO EO EE OO EO EO OO EE Final diagram is: