Re: (f)lex Regular Expression for C++ comment.

vern@daffy.ee.lbl.gov (Vern Paxson)
1 Mar 1996 17:57:59 -0500

          From comp.compilers

Related articles
(f)lex Regular Expression for C++ comment. pwk@news.eb.ele.tue.nl (1996-03-01)
Re: (f)lex Regular Expression for C++ comment. vern@daffy.ee.lbl.gov (1996-03-01)
| List of all articles for this month |
From: vern@daffy.ee.lbl.gov (Vern Paxson)
Newsgroups: comp.compilers
Date: 1 Mar 1996 17:57:59 -0500
Organization: Lawrence Berkeley Laboratory, Berkeley CA
References: 96-03-019
Keywords: lex

> [I strongly discourage attempts to handle comments this way, because they
> fail as soon as a comment is longer than the token buffer. It's easy to do
> this with exclusive start states, e.g.:
>
> %x COMMENT
> %%
> "/*" begin COMMENT ;
> <COMMENT>"*/" begin NORMAL;
> <COMMENT>.|\n /* ignore */;


Flex's own scanner (written in flex) deals with C comments. It uses
slightly more complicated rules than John gives above, in an effort
to match as much text as possible, to improve performance. (But not
more than one line at a time, for the reason John mentions.)


<COMMENT>{
"*/" ACTION_ECHO; yy_pop_state();
"*" ACTION_ECHO;
[^*\n]+ ACTION_ECHO;
[^*\n]*{NL} ++linenum; ACTION_ECHO;
}


- Vern
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.