CSci 3501 Algorithms and Computability - Lab 8.

October 28. Due Tuesday, November 4th at 11:59pm

What to submit and when:

Lab assignment

Work in pairs

Lab overview and goals

The goals of this lab are:

  1. To study conversions between regular expressions and finite automata using JFLAP
  2. To study the pumping lemma using JFLAP
  3. To learn and practice Java regular expressions

Convert a regular expression to an NFA

Use the tutorial Regular Expressions and Converting to an NFA to convert the regular expressions given below to NFAs. Note that JFLAP uses + as a symbol for union and * for the star operation. Also make sure to set parentheses correctly in your expression.

JFLAP gives you hints on the steps and provides a button "(D)e-expressionify Transition" to break down regular expressions into smaller subexpressions. You need to add the empty transitions to complete each step.

As you are converting a regular expression to an NFA, write down the intermediate exressions as a note on the JFLAP screen: use the selection tool (the one that you use to mark initial and final states), right-click anywhere on the JFLAP screen, and choose "add note". For instance, if you are breaking down an expression 00+11 into 00 and 11, write 00+11 -> 00, 11. Also add a note clearly describing (in English) the language defined by the given regular expression.

When you are done, go to Export and export the resulting NFA, then test it and save it.

Below are the regular expressions:

  1. ((0+1)0)*
  2. (00)*+(10)*

Convert a DFA to a regular expression

JFLAP guides you through the process of converting a DFA to a regular experssion via a generalized NFA (GNFA), as described in the tutorial Converting a FA to a Regular Expression. JFLAP uses a slightly different version of a GNFA: it allows self-loops in the starting and the final state. The empty set transitions are added just like in the book, and the number of states is reduced by the procedure described in the book. The resulting regular expression then is combined as R1*R2R3*, where R1 is the self-loop expression in the start state, R2 is the expression on the transition from the start state to the final state, and R3 is the loop in the final state.

As you are transforming your DFA to a 2-state GNFA, write down (in a plain-text file) all transition changes that result in a non-empty-set expressions.

Below are the DFAs to convert:

  1. The language of all strings with 00 pattern
  2. The language of all strings that either start with 0 and don't have any more 0s, or start with 1 and don't have any more 1s. Note that as the first step you would need to create a single final state and connect the old final states to it by empty-string transitions.

Please export and submit your resulting expression.

Play the "pumping lemma game"

The pumping lemma in JFLAP is implemented as a two-player "game" when one player is trying to prove that a language is regular by representing strings as required by the pumping lemma, and the other player is trying to disprove it, as described in the tutorial Regular Pumping Lemmas.

Go to "Regular Pumping Lemma" in the JFLAP start menu (careful: you don't want Context-Free Pumping Lemma). There is a list of languages, some regular, some aren't. The alphabet is a,b. The pumping length is denoted as m. JFLAP allows you to save the file with the log of all your attempts. Please submit these fiels for the two cases below and additionally write down your conclusions in a plain-text file or an e-mail message. Your conclusions should include: whether the language satisfies the pumping lemma (show an example that breaks it or briefly describe a strategy that makes it work) and whether it is regular (note that some languages that satisfy the pumping lemma may still be non-regular).

The languages to try:

  1. The 6th example (the language a^n b^j a^k, where n > 5, j > 3, and k ≤ j). Choose the "computer goes first" option so that you are trying to prove that the language is non-regular.
  2. The 8th example (the language a^n b^k, n is odd or k is even). Choose the "you go first" option so that you are trying to prove that the language satisfies the pumping lemma.

Use Java regular expressions to define a pattern

Study the Java regular expressions tutorial. Note that instead of using the Pattern and Matcher classes directly, you will be using the class RegExTester that provides methods for searching, splitting, and replacing strings based on regular expressions.

It is important to know that by default regular expressions will try to find a matching sequence within the given input, not match the entire input.

Your tasks are as follows. Assume case-insensitive matches, unless specified otherwise.

  1. Find all occurrences of letter combinations "dfa" and "nfa" in a text.
  2. Find all integer numbers (i.e. sequences of digits with no other characters) in a text.
  3. Find all negative integer numbers, i.e. numbers preceded by a - sign
  4. Find all words that start with a letter t
  5. Find all words in a text that have letters t and/or i in the them (in any order)
  6. Check whether a given text has exactly three question marks in it (hint: use boundary markers)
  7. Check whether a given text has at most three question marks in it
  8. Use the doRegExSplit to split a string into items separated by |
  9. Use the doRegExReplace method to replace all occurrences of "today" by "yesterday".

Make sure to submit your code (with some method calls commented out) and a copy of your test data for each regular expression (as a separate file or in comments).

Using JFLAP and naming your files

What to submit


CSci 3501 course web site.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.