COMS W4115
Programming Languages and Translators
Homework Assignment #1
Due in class, 2:40pm, February 20, 2012
Instructions
- Do this assignment by yourself.
- You may consult the instructor or a TA for clarification,
but no other people.
- Problems (1-4) are each worth 25 points.
- Solutions to these problems will be posted
on February 27, 2012.
- This assignment may be handed in by February 27, 2012 for 50% credit.
Problems
- Construct Lex-style regular expressions for the following patterns.
For each pattern, create a Lex program to find the first longest lowercase word
in the dictionary satisfying that pattern. As part of your
answer list your program and the longest word found. State what dictionary
you used (e.g., on Linux systems
/usr/dict/words).
- All lowercase English words ending in
dous.
- All lowercase English words with exactly one vowel.
For this question treat
a,e,i,o,u as the vowels.
- All lowercase English words with exactly one consonant.
- All lowercase English words with the subsequence
aeiou.
- All lowercase English words in which the letters are strictly monotonically
decreasing lexicographically as in
skied.
- Let L be the language consisting of all
strings of 0's and
1's representing integers that are divisible by 3.
Assume the empty string represents 0.
- Construct a deterministic finite automaton
(DFA) for L.
- Minimize the number states in your DFA.
- Explain what property of the input each state in your DFA recognizes.
- From your minimized DFA construct a regular expression for L.
- Show how your automaton processes 1100.
- Use the pumping lemma for regular languages to show that the language
consisting of all strings of
a's and b's with an unequal number of
a's and b's is not regular.
- Let L be the language consisting of all strings of
a's and b's with the same number of substrings ab
as ba.
Note that aba contains one substring ab and one substring
ba. In contrast, abab has two ab's but only
one ba. Construct a regular expression for L.
Prove that your regular expression is correct.
aho@cs.columbia.edu