Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!uflorida!novavax!twwells!bill From: bill@twwells.com (T. William Wells) Newsgroups: comp.lang.c Subject: Re: LEX rule, anyone??? Message-ID: <1989Dec6.180833.2985@twwells.com> Date: 6 Dec 89 18:08:33 GMT References: <601@vice2utc.chalmers.se> <224@bohra.cpg.oz> Organization: None, Ft. Lauderdale, FL Lines: 28 In article <224@bohra.cpg.oz> ejp@bohra.cpg.oz (Esmond Pitt) writes: : 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. (It should not be: the */ is longer than the `.' rule. Or is INITIAL as a start state treated specially?) : %start COMMENT : %% : "*/" BEGIN(INITIAL); : .|\n ; : "/*" BEGIN(COMMENT); : : If you are using lex you will find this slow Not only that, but start states are not reliable with lex. After being bitten by them for the n'th time, I switched to flex. --- Bill { uunet | novavax | ankh | sunvice } !twwells!bill bill@twwells.com