LEX rule, anyone???
Mike Haertel
mike at wheaties.ai.mit.edu
Wed Dec 6 08:39:39 AEST 1989
In article <2191 at prune.bbn.com> rsalz at 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 <mike at ai.mit.edu>
"Everything there is to know about playing the piano can be taught
in half an hour, I'm convinced of it." -- Glenn Gould
More information about the Comp.lang.c
mailing list