regex for C comments
Randal Schwartz
merlyn at iwarp.intel.com
Tue Jul 11 05:03:09 AEST 1989
In article <19365 at paris.ics.uci.edu>, schmidt at zola (Doug Schmidt) writes:
| In their book ``Introduction to Compiler Construction with UNIX,''
| Schreiner and Friedman provide the following LEX regular expression
| for recognizing C comments:
|
| ----------------------------------------
| "/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/"
| ----------------------------------------
|
| Ignoring the possibility of overflowing an internal LEX buffer,
| does anyone know of any legal C comments that fail to match
| with this regular expression?
Try:
/***/
(This one was easy. :-)
The problem with this one is that
"star" "not-slash"
can match
"star" "star"
where the second star is sometimes the first star of the terminating
"star" "slash"
This is a common problem with these regex's. Now come on people,
is this one of those "20 most commonly asked questions in comp.lang.c"?
And who has the right answer? (Not me.... I screwed up last time... :-)
Just another C hacker,
--
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel, Hillsboro, Oregon, USA |
| merlyn at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/
More information about the Comp.lang.c
mailing list