CSci 3501 Algorithms and Computability - Lab 9.

October 20. Due Wednesday, October 26 at 11:59pm

What to submit and when:

Lab assignment

Work in pairs

Lab overview and goals

The goal of the lab is to explore combining finite automata, conversion between DFAs, NFAs and regular expressions, and to get practice with regular expression.

Using JFLAP and naming your files

Lab tasks, part 1 (12 points total: 3 for each question)

Unless specified otherwise, the alphabet is the set of 0 and 1.

  1. Construct an automaton (DFA or NFA) for a concatenation of the following languages: a language of all strings of an odd length and a language of strings that can be represented as a non-empty sequence of 1s followed by a non-empty sequence of 0s. Test the automaton carefully.
  2. Construct an automaton (DFA or NFA) for A* (* stands for the "star" regular operation), where A is the language of strings of length at least two with no occurrences of the pattern 00. Think carefully of what the language is. Use the * construction for NFA. Test the automaton thoroughly.
  3. Use the "convert to DFA" function of JFLAP to convert an NFA for the language of all strings with at least two 0s to a DFA.
  4. Use the "convert to DFA" function of JFLAP to convert an NFA for the language of all strings that end with two 1s to a DFA.

Lab tasks, part 2: Convert a regular expression to an NFA (8 points)

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 expressions 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.

Below are two regular expressions to convert:

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

Please export and submit your resulting expression.

Part 3: Java regular expressions (21 points)

Study the Java regular expressions tutorial (ignore the Test Harness section, we use our own testing class). 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. Study examples in main in that class.

Important: by default regular expressions will find a matching sequence within the given input; they do not match the entire input. For instance, a regular expression "DFA" will find a match in an input "DFAs are cool".

Also important: Java strings use \ as a special character. Therefore you need \\ for predefined regex classes, e.g. "\\d+" matches one or more digit. See a link to more predefined classes in question 2 below.

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. Use a predefined class \d to match a single digit (see example here: http://java.sun.com/docs/books/tutorial/essential/regex/pre_char_classes.html ).
  3. Find all negative integer numbers, i.e. numbers preceded by a - sign
  4. Find all words that start with a letter t (hint: use boundary matches http://java.sun.com/docs/books/tutorial/essential/regex/bounds.html
  5. Find all words in a text that have letters t and/or i in the them (in any order)
  6. Use the doRegExSplit to split a string into items separated by |
  7. 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).

What to submit


CSci 3501 course web site.