CS536 Homework 1
Fall 2018
Due by 11:59 pm on Friday, October 12, 2018 (not accepted late)

Questions

Homework assignments must be done individually. Collaboration on homework assignments is not allowed.

Question 1:

Java (as well as C and C++) allows comments delimited by "/*" and "*/". This kind of comment can be defined in English as follows:

A comment consists of three parts:
  1. a slash followed by a star, followed by
  2. the body of the comment, followed by
  3. a star followed by a slash.
The body of the comment can be empty, or can contain any characters except the two-character sequence "*/".

Note that the body of a comment can include stars and slashes, just not "*/".

Assume that the following JLex macros have been defined:

SLASH     = [/]
STAR      = [*]

Label each of the following JLex patterns as being correct/incorrect for the type of the comment described above.

  1. {SLASH}{STAR}(.)*{STAR}{SLASH}
  2. {SLASH}{STAR}[^(*/)]*{STAR}{SLASH}
  3. {SLASH}{STAR}([^*]|[^/])+{STAR}{SLASH}
  4. {SLASH}{STAR}([^*]|({STAR}+[^*/]))*{STAR}{SLASH}
  5. {SLASH}{STAR}[^*]*{STAR}+{SLASH}
  6. {SLASH}{STAR}([^*]|({STAR}+[^*/]))*{STAR}+{SLASH}
For each incorrect pattern, explain what is wrong. For example, you might say The pattern does not allow the comment body to include stars, or The pattern does allow the comment body to include */.

If the pattern both disallows some "good" comments and allows some "bad" comments, give two explanations, one for each problem with the pattern.

Then, for each problem with the pattern, give a string that illustrates the problem; i.e., give a string that is not matched by the pattern but is a "good" comment and/or give a string that is matched by the pattern but is a "bad" comment.

Be sure that it is clear whether your example strings are intended to be "good" or "bad" comments.

Handing in

Please include your name at the top your file.

Put your answers to all questions into one file named Homework1 with the appropriate file extension, e.g., Homework1.pdf

Electronically submit your work to the Homework 1 tab on Canvas.

Last Updated: 7/31/2018     © 2018 Charles Fischer