Computer Science 5641
Compiler Design
Homework Assignment 1 (20 points)
Due September 24, 2002

  1. [9] Consider a definition of strings as follows:
    1. Draw a DFA that recognizes this language
    2. Write a regular expression that defines this language
    3. Convert your regular expression into an NFA
  2. [5] Some programming languages allow integer constants to be written in other bases (e.g., base 8, 10, 16). Consider a language of integer constants where base 8 numbers start with a 0 and may contain digits from 0 to 7, base 10 integer constants start with any digit other than zero and can include digits from 0 to 9, and base 16 numbers start with an X and can include digits 0 through 9 as well as letters A through F -- 10 (A), 11 (B), 12 (C), 13 (D), 14 (E), 15 (F).
    1. Draw a DFA that recognizes this language
    2. Write a regular expression that defines this language
  3. [6] Implement a scanner using flex (or lex) for the language discussed in the previous question and show that your recognizer works on a test file. Assume that the constants are separated by white space characters (space, tab, newline) and that the file contains no other characters. Your output should show the original lexeme as well as the corresponding token in base 10.