Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!murtoa.cs.mu.oz.au!ditmela!yarra!bohra!ejp From: ejp@bohra.cpg.oz (Esmond Pitt) Newsgroups: comp.lang.c Subject: Re: LEX rule, anyone??? Message-ID: <224@bohra.cpg.oz> Date: 6 Dec 89 01:49:18 GMT References: <601@vice2utc.chalmers.se> Reply-To: ejp@bohra.cpg.oz (Esmond Pitt) Organization: Computer Power Group, Melb, Australia Lines: 41 In article <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? You don't want to do this in one rule, because a sufficently long C comment will overflow lex's token buffer, with dire results. Three rules do it; the order is important. %start COMMENT %% "*/" BEGIN(INITIAL); .|\n ; "/*" BEGIN(COMMENT); If you are using lex you will find this slow, so you will probably replace the above with something like this: %% "/*" { int c; for(;;) { c = input(); if (c == '*') { c = input(); if (c == '/') break; unput(c); } } } (E&OE) -- Esmond Pitt, Computer Power Group ejp@bohra.cpg.oz