Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site harvard.ARPA Path: utzoo!watmath!clyde!bonnie!akgua!whuxlm!harpo!decvax!genrad!panda!talcott!harvard!dudek From: dudek@harvard.ARPA (Glen Dudek) Newsgroups: net.unix Subject: Re: comments in lex Message-ID: <232@harvard.ARPA> Date: Wed, 3-Jul-85 18:42:39 EDT Article-I.D.: harvard.232 Posted: Wed Jul 3 18:42:39 1985 Date-Received: Fri, 5-Jul-85 06:09:18 EDT Distribution: net Organization: Aiken Computation Laboratory, Harvard Lines: 30 What I consider the "best" (read "most efficient") way to eat C or PL-1 style comments in lex is as in the ANSI-C standard yacc/lex grammar recently posted to the net: %% "/*" { comment(); printf("comment"); } %% comment() { char c, c1; loop: while ((c = input()) != '*' && c != 0) putchar(c); if ((c1 = input()) != '/' && c != 0) { unput(c1); goto loop; } if (c != 0) putchar(c1); } My favorite way is to use the following lex expression: %% "/*"("/"|("*"*[^*/]))*"*"+"/" { printf("comment"); } %% Although it may make your head hurt, it's interesting to figure out. Glen Dudek