CS 412/413
Introduction to Compilers and Translators
Spring 2000

Homework 1: Lexical Analysis

due: Monday, January 31, in class

  1. 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.
    1. Write a regular expression that recognizes exactly C comments. Use the syntax [^chars] to indicate the possibility of any character except the characters listed in chars.
    2. Some implementations of C permit nested comments. Why can't you write a regular expression to recognize this extended syntax for comments?
  2. Appel, problem 2.1 (a, f)
  3. Appel, problem 2.3
  4. Appel, problem 2.6
  5. Appel, problem 2.9