Path: utzoo!attcan!uunet!lll-winken!decwrl!orc!mipos3!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.c Subject: Match C Comments... the right answer (was Re: LEX rule, anyone???) Message-ID: <5365@omepd.UUCP> Date: 17 Dec 89 20:08:37 GMT References: <601@vice2utc.chalmers.se> <2191@prune.bbn.com> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 28 In-reply-to: rsalz@bbn.com (Rich Salz) In article <2191@prune.bbn.com>, rsalz@bbn (Rich Salz) writes: | In <601@vice2utc.chalmers.se> d5kwedb@dtek.chalmers.se (Kristian Wedberg) writes: | >A question from a friend of mine, P{r Eriksson: | > Does anyone know how to write a LEX rule for C comments, | > ie for everything between /* and */, nesting not allowed? | | We go through this in comp.lang.c about once a year. Almost everyone | gets it wrong. The best thing to do is to define a lex rule that | catches "/*" and in the actions for that rule look for */ on your own. OK, almost everyone got it wrong (and I took great delight at pointing out what was wrong sometimes :-), but there was ONE correct answer -- mine ( :-)... "/*"(\**[^*/]|\/)*\*+\/ Don't accept any cheap imitations. They're probably wrong. (This one is wrong in that it will match C comments inside of text strings, but that's just plain pathological. :-) (No, I don't have one in Perl... :-) Just another regex hacker, -- /== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\ | on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/