This definition is invalid:
comment [["//"[.]*\n] | ["/\*"[.]*"\*/"]]
[
and (
are different. [...]
is a character-class; that is, a list of possible characters which will match a single character. (...)
is used to group regular expressions.
Also, I don't believe you can insert arbitrary space characters in a Flex++ regex.
So I think that what you intended was:
comment ("//".*\n|"/*".*"*/")
Here I've removed the incorrect square brackets, changed the ones which were used for grouping into parentheses, and removed the unnecessary grouping around the alternatives, since |
has lower precedence than concatenation. I also removed the unnecessary backslash escapes, since quoting is sufficient to make a *
into a character.
However, that will not correctly match C++ comments:
First, .*
is greedy (i.e., it will match the longest possible string) so
/* A comment */ a = 3; /* Another comment */
will be incorrectly recognized as a single comment.
Second, .
does not match a newline character. So multi-line /* ... */
comments won't match, because .*
won't reach to the end of the comment, only to the end of the line.