• Home
  • Queen's University
  • Software Specifications
  • Equivalence of Regular Expressions and State Diagrams

Equivalence of Regular Expressions and State Diagrams

CISC/CMPE-223, Winter 2023, Regular expressions and state diagrams 1 Converting regular expressions to state diagrams and vice versa Up to now we have considered two language specification mechanisms: regular expressions and state diagrams. We show that regular expressions and state diagrams define exactly the same class of languages. This fact is remarkable because superficially state diagrams and regular expressions appear to be quite different. To show that regular expressions and state diagrams are equivalent we need to do the conversion in both directions. This material is from Chapter 9 in the textbook. Converting regular expressions to state diagrams For an arbitrary regular expression we construct an equivalent nondeterministic state diagram with E-transitions that satisfies the following conditions: 1. There is exactly one accepting state and it is distinct from the start state. 2. There are no transitions into the start state. 3. There are no outgoing transitions from the accepting state. The recursive construction relies on the fact that the previously constructed state-transition diagrams satisfy the above conditions 1., 2., 3. (In general, an E-NFA does not need to satisfy the above three conditions.) The state diagrams for the base cases (i) E = Ø, (ii) E = €, (iii) E = a, (a € 2) are depicted in Figure 1. Inductive step: Next suppose that Ei, i = 1,2, are regular expressions and we have con- structed a state diagram Si that is equivalent to E; and satisfies the conditions 1., 2., 3. An CISC/CMPE-223, Winter 2023, Regular expressions and state diagrams 2 (i) E = 0 (ii) E = € - (iii) E = a ? ? ? a ? ? ? Figure 1: State diagrams for the base cases. abstract representation of Si is given in Figure 2: Si has no incoming transtions to start state, has one accepting state, and no outgoing transitions from the accepting state. Figure 2: State diagram Si that is constructed for the regular expression Ei, i = 1, 2. For the inductive step we have to show how to construct state diagrams for the regular expressions E1 + E2, E1 . E2 and El. (iv) The state diagram for E1 + E2 is depicted in Figure 3. The resulting state diagram has all states of S1 and S2 with the exception that the start states (respectively, the accepting states) of S1 and S2 are merged together. The conditions 1., 2., 3. guarantee that the constructed state diagram accepts exactly the strings accepted by S1 and the CISC/CMPE-223, Winter 2023, Regular expressions and state diagrams 3 strings accepted by S2 (more details explained in class). Note that the resulting state diagram again satisfied the conditions 1., 2., and 3. Figure 3: State diagram for regular expression E1 + E2. (v) The state diagram for the regular expression E1 · E2 is constructed by merging the accepting state of S1 with the start state of S2 and the merged state is not accepting. The construction is depicted in Figure 4. Again the conditions