CS536 Homework 1 Solution
Question 1:
Question 2: (one possible solution)
[letter]([letter] | [digit] | [hyphen]([letter] | [digit]))*#[digit]+
Question 3:
{SLASH}{STAR}[^(*/)]*{STAR}{SLASH}
- Incorrect
- Doesn't allow parentheses, stars, or slashes in the comment body: /* (*)(/) */
{SLASH}{STAR}(.)*{STAR}{SLASH}
- Incorrect
- Allows */ in the comment body: /* a */ */
- Doesn't allow a newline in the comment body:
/* this is a
multi-line comment */
{SLASH}{STAR}([^*]*{STAR}+[^*/])*{STAR}+{SLASH}
- Incorrect
- Doesn't allow a non-empty comment body without a star: /* a */
{SLASH}{STAR}([^*]|[^/])+{STAR}{SLASH}
- Incorrect
- Allows */ in the comment body: /* */ */
- Doesn't allow a comment with an empty body: /**/
{SLASH}{STAR}[^*]*{STAR}+{SLASH}+
- Incorrect
- Allows multiple / after the end of the comment: /* *////
- Doesn't allow non-star to appear after a star in the comment body: /* *a */
{SLASH}{STAR}([^*]|({STAR}+[^*/]))*{STAR}+{SLASH}
- Correct
Question 4:
{SLASH}{SLASH}([^\n]*)\n
OR
{SLASH}{SLASH}(.)*\n