COMS W4115
Programming Languages and Translators
Homework Assignment #1
Due in class, 2:40pm, February 20, 2012


Instructions

Problems

  1. 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).
    1. All lowercase English words ending in dous.
    2. All lowercase English words with exactly one vowel. For this question treat a,e,i,o,u as the vowels.
    3. All lowercase English words with exactly one consonant.
    4. All lowercase English words with the subsequence aeiou.
    5. All lowercase English words in which the letters are strictly monotonically decreasing lexicographically as in skied.

  2. 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.
    1. Construct a deterministic finite automaton (DFA) for L.
    2. Minimize the number states in your DFA.
    3. Explain what property of the input each state in your DFA recognizes.
    4. From your minimized DFA construct a regular expression for L.
    5. Show how your automaton processes 1100.

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

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