Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!snorkelwacker!ai-lab!mike From: mike@wheaties.ai.mit.edu (Mike Haertel) Newsgroups: comp.lang.c Subject: Re: LEX rule, anyone??? Message-ID: <5340@rice-chex.ai.mit.edu> Date: 5 Dec 89 21:39:39 GMT References: <601@vice2utc.chalmers.se> <2191@prune.bbn.com> Reply-To: mike@ai.mit.edu (Mike Haertel) Organization: Free Software Foundation Lines: 25 In article <2191@prune.bbn.com> rsalz@bbn.com (Rich Salz) 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. I've done this before. I think the regexp I used was (ick!): "/*"([^*]*("*"[^/])?)*"*/" Despite the fact that you *can* do it, you don't want to. The reason is that lex has a fixed length buffer into which the text of the entire token must fit. This is arguably brain damaged (in fact there is an option to set the buffer length, but one might argue that the buffer should dynamically resize). If you think about it, it's kind of silly to carefully read in all of something you're going to throw away anyway. Which is yet another reason why the method rsalz suggests is recommended. -- Mike Haertel "Everything there is to know about playing the piano can be taught in half an hour, I'm convinced of it." -- Glenn Gould