CSci 3501 Algorithms and Computability - Lab 9.

November 4th. Due Tuesday, November 11th 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 context free grammars (CFG) and pushdown automata using JFLAP
  2. To continue looking at Java regular expressions

CFG and pushdown automata

Use the corresponding sections of JFLAP tutorial as a reference. Define the following:

  1. A context free grammar for odd-length strings of alternating zeros and ones
  2. A context free grammar for the language of strings a^n b^m, where n >= m
  3. A context free grammar for the language of strings a^k followed by any number of b followed by c^k
  4. A pushdown automaton for the language of strings a^k followed by any number of b followed by c^k (do not convert your grammar from the previous question into an automaton or vice versa)
  5. A pushdown automaton for a language of strings of odd length with the middle symbol 0.

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.

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

  1. A 10-digit phone number may be written in a variety of different ways (with or without dashes, spaces, parenteses for area code, etc.). Write a regular expression that recognizes reasonable ways of entering a phone number. In comments please list accepted formats. Try to make your expression concise and readable. Do not check for specific digits, i.e. (000) 000-0000 should be allowed.
  2. Write a regular expression to check if a text has more than 3 html links. A link is written as
    <a href="...the url...">text</a>
    . Try your program on a few web pages.
  3. Read about the greedy, reluctant, and possessive quantifiers, and make your expression for the previous question so that it uses the matches on href and wildcard only.

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.