home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 18900 < prev    next >
Encoding:
Text File  |  1992-12-26  |  1.1 KB  |  31 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!uniteq
  3. From: uniteq@netcom.com (Uniteq Application Systems)
  4. Subject: Re: Wanted: program to extract comments from C
  5. Message-ID: <1992Dec26.095028.29823@netcom.com>
  6. Organization: Uniteq Application Systems
  7. References: <1h580nINN11p@life.ai.mit.edu>
  8. Date: Sat, 26 Dec 1992 09:50:28 GMT
  9. Lines: 20
  10.  
  11. In article <1h580nINN11p@life.ai.mit.edu> kenneths@ai.mit.edu (Kenneth J. Schneider) writes:
  12. >well, i just hacked this lex file together:
  13. >
  14.  
  15. It's OK, but you could also do it with a lot fewer lines (and a much
  16. more complicated engine, but we let lex worry about that stuff):
  17.  
  18. %%
  19. "//".*                {printf("%s\n", yytext); /* C++ comments */ }
  20. "/*"([^*]|\*+[^*/])*\*+\/    {printf("%s\n", yytext); /* std C comments */ }
  21. .|\n                { /* ignore everything else */ }
  22.  
  23. I am uncertain about the correct semantics when mixing the two commenting
  24. styles - the above code allows `//' to comment out a `/*' but not a `*/'.
  25. The code Kenneth presented took the rather strange (IMO) stance of making
  26. either type of comment able to override the other (`//' remains active
  27. within a `/* ... */' pair).
  28.  
  29. Enjoy,
  30.         - Jeff.
  31.