lex grammar for C comments

Prescott K. Turner turner at sdti.UUCP
Fri Apr 8 02:50:00 AEST 1988


 
In article <262 at nyit.UUCP>, michael at nyit.UUCP (Michael Gwilliam) answered
the question, 
>"Can C comments be filtered out with LEX as regular expressions?" 

The answer
>"Yes, but it may not be a good idea."
is the right one.  He goes on to say
>_Introduction_to_Compiler_Construction_with_Unix_, by Axel T. Schreiner and
>H. George Friedman, Jr., Prentice-Hall, 1985, on page 25 gives:
>
>        "/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/"

I did not notice the original question on the net, but recently struggled
with the same regular expression problem.  So I respect the above solution,
even though it erroneously matches

        /***//*/

as a complete comment.  Here is a correct regular expression for a C comment:

        "/*""/"*("*"*[^*/]"/"*)*"*"*"*/"
--
Prescott K. Turner, Jr.
Software Development Technologies, Inc.
375 Dutton Rd., Sudbury, MA 01776 USA        (617) 443-5779
UUCP:...genrad!mrst!sdti!turner



More information about the Comp.lang.c mailing list