Homework 2 Solution
Question 1:
{SLASH}{STAR}[^(*/)]*{STAR}{SLASH}
- Doesn't allow parentheses, stars, or slashes in the comment body: (good comment example) /* (*)(/) */
{SLASH}{STAR}(.)*{STAR}{SLASH}
- Allows */ in the comment body: (bad comment example) /* a */ */
- Doesn't allow a newline in the comment body: (good comment example)
/* this is a
multi-line comment */
{SLASH}{STAR}([^*]*{STAR}+[^*/])*{STAR}+{SLASH}
- Doesn't allow a non-empty comment body without a star: (good comment example) /* a */
{SLASH}{STAR}([^*]|[^/])+{STAR}{SLASH}
- Allows */ in the comment body: (bad comment example) /* */ */
- Doesn't allow a comment with an empty body: (good comment example) /**/
{SLASH}{STAR}[^*]*{STAR}+{SLASH}+
- Allows multiple / after the end of the comment: (bad comment example) /* *////
- Doesn't allow non-star to appear after a star in the comment body: (good comment example) /* *a */
Question 2:
{SLASH}{STAR}([^*]|({STAR}+[^*/]))*{STAR}+{SLASH}