CS 412/413
Introduction to Compilers
Spring 2002

Homework 1: Lexical Analysis

due: Friday, February 1, in class

  1. A floating point number contains a numeric part followed by an optional exponent. The numeric part may be a positive or negative integer, or a number containing a decimal point and at least one digit on the left- or right-hand side. The numeric part may not start with leading zeros unless the zero is the only digit to the left of the decimal point. The exponent starts with either the character "e" or "E", followed by either a positive or negative integer. Write a concise regular expression that captures this definition.
  2. A comment in the C language begins with the two-character sequence "/*", followed by the body of the comment, and then the sequence "*/". The body of the comment may not contain the sequence "*/", although it may contain the "*" and "/" characters. Write regular expressions for each of the following, or explain why there is no regular expression defining it. 
    1. exactly C comments.
    2. C comments, permitting intervening "*/" which appears inside quotes.
    3. C comments, permitting nested comments.
  3. Appel, problem 2.3 (a,c)
  4. Appel, problem 2.5 (a)
  5. Appel, problem 2.6
  6. Appel, problem 2.7
  7. Appel, problem 2.9