CSci 3501 Algorithms and Computability - Lab 9.
November 4th. Due Tuesday, November 11th at 11:59pm
What to submit and when:
- All submissions are electronic: by e-mail to elenam at morris.umn.edu and CC to all lab
partners. Please do not delete your e-mail from "Sent mail" or your
mailbox until the end of the semester.
- When working on the lab, please comment your work so that it is
clear what contributions of each person are.
- At the end of the lab each group should send me the results of their
in-class work. Please indicate if this is your final submission.
- If your submission at the end of the lab time was not final,
please send me(CC to the lab partner(s)) a final copy before the due
time. Please use the subject "3501 Lab N", where N is the lab
number.
Lab assignment
Work in pairs
Lab overview and goals
The goals of this lab are:
- To study context free grammars (CFG) and pushdown automata using JFLAP
- To continue looking at Java regular expressions
CFG and pushdown automata
Use the corresponding sections of JFLAP tutorial as a reference.
Define the following:
- A context free grammar for odd-length strings of alternating zeros and ones
- A context free grammar for the language of strings a^n b^m, where n >= m
- A context free grammar for the language of strings a^k followed by any number of b followed by c^k
- 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)
- 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.
- 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.
-
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.
- 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
- Please save your automata files as .jff files and your data as .txt files. Files names must be as follows: names of those in the group followed by question name, e.g.
SmithAdams3.jff
(where 3 refers to the question number). This will help me in running test data
- To load test data from a file, go to
Input -> Multiple Runs -> Load Inputs
- When adding multiple transitions between the same two states, add them one by one. Typing "0, 1" in a label for an arrow will give you a wrong result since the automaton will try to match this input exactly, including the comma.
- When writing DFA, check that every state has a transition on every symbol. JFLAP does not check it.
- Use
Convert -> Combine Automata
to copy one automaton into a file for another one.
- Consult the JFLAP tutorial as
needed.
What to submit
- Submit your JFLAP files as attachments, CC your group. Make sure
to submit your automata
files (as .jff) and your input data (as .txt). Make sure to follow the naming requirements! Make it clear which
data refers to which automaton.
CSci 3501
course web site.