Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!ncar!tank!mimsy!tove.umd.edu!cml From: cml@tove.umd.edu (Christopher Lott) Newsgroups: comp.lang.c Subject: Re: LEX rule, anyone??? Message-ID: <21108@mimsy.umd.edu> Date: 5 Dec 89 15:42:39 GMT References: <601@vice2utc.chalmers.se> Sender: news@mimsy.umd.edu Reply-To: cml@tove.umd.edu (Christopher Lott) Organization: The University of Maryland Dept of Computer Science Lines: 27 In article <601@vice2utc.chalmers.se> d5kwedb@dtek.chalmers.se (Kristian Wedberg) writes: > Does anyone know how to write a LEX rule for C comments, > ie for everything between /* and */, nesting not allowed? [ because I would love to see other solutions to this, I posted. ] This sounds suspiciously like someone's homework assignment. In fact, I had exactly such a homework assignment, and this resulted :-) The following lines are a lex program to recognize c comments, not nested. This does NOT take into account any quote marks within a comment; i.e., quote marks don't 'escape' the close comment marker. I compile this via "lex ccom.l ; cc lex.yy.c -o ccom -ll" ----snip---- /* this is a regular expression to match a c comment */ /* written by cml 890922 (probably not minimal) */ %% "/*"([^*]|[*]*[^*/])*[*]+"/" {printf("saw a c comment.\n");} . {putchar(*yytext);} ----snip---- chris... -- cml@tove.umd.edu Computer Science Dept, U. Maryland at College Park 4122 A.V.W. 301-454-8711