LEX rule, anyone???

T. William Wells bill at twwells.com
Thu Dec 7 05:08:33 AEST 1989


In article <224 at bohra.cpg.oz> ejp at bohra.cpg.oz (Esmond Pitt) writes:
: In article <601 at vice2utc.chalmers.se> d5kwedb at 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
: %%
: <COMMENT>"*/" BEGIN(INITIAL);
: <COMMENT>.|\n ;
: <INITIAL>"/*"                 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 at twwells.com



More information about the Comp.lang.c mailing list