Computer Science 5641
Compiler Design
Homework Assignment 1 (20 points)
Due September 24, 2002
- [9] Consider a definition of strings as follows:
- A string starts with a single double quote character
- A string ends with a single double quote character
- A string may contain letters, digits and escaped double quote characters
- A double quote character is escaped by preceding it with a slash character
- Draw a DFA that recognizes this language
- Write a regular expression that defines this language
- Convert your regular expression into an NFA
- [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).
- Draw a DFA that recognizes this language
- Write a regular expression that defines this language
- [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.