Question: Write a regular expression for comments of the form /* .... */. Haskell -The comment begins with /* and end with the first */ encountered.
Write a regular expression for comments of the form /* .... */.
Haskell
-The comment begins with /* and end with the first */ encountered. -Optional whitespace can precede the comment or follow the comment, but nothing else. Whitespace -consists of spaces and or tabs (\t). Don't include newline ( ). -The text of the comments can include letters or digits, space, tab, underscore, *, and /. - The comment can include /*, but we don't nest comments. -The star of the beginning /* cannot be the star of the ending */. -The symbol before the ending */ doesn't have to be whitespace. -Inside a regular expression, if you want a star symbol, escape it as \*, since just * means Kleene star. (So within the expression, write /\* to mean a slash followed by a star. As an expression, just /* means zero or more slashes)
Some strings that should fail to match: /* xyz */ */ By rules 1 and 2 /* /* xyz */ */ By rules 1, 2, and 4 /*/ By rule 5
Some strings that should match: /**/ By rules 3, 5, and 6 /*///***/ By rules 3, 5, and 6 /* * * Typical * * */ By rules 2 and 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
