help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to recognize a multiple line comment ?


From: Nicolas Peyrussie
Subject: Re: how to recognize a multiple line comment ?
Date: Thu, 07 Apr 2005 09:24:20 +0200
User-agent: Mozilla Thunderbird 1.0.2-1.3.2 (X11/20050324)

Hi,

I recognize and avoid html comments on multiple lines like this :
<INITIAL>"<!--"                  {yy_push_state(COMMENT);}
<COMMENT>"-->"              {yy_pop_state();}
<COMMENT>"\n"                {}
<COMMENT>.                      {}

So you have to do something like this; yy_push_state() adds COMMENT state on top of the stack, it is declared as exclusive (%x), and then you pop it at the end of the comment detection with yy_pop_state(), if you want to keep all I think you have to add yymore() on <COMMENT>"\n" {yymore();} and <COMMENT>. {yymore();}.

So something like this
<INITIAL>"/*"                  {yy_push_state(COMMENT);}
<COMMENT>"*/"            {
                                              /* add the action here*/
                                              yy_pop_state();
                                            }
<COMMENT>"\n"                {yymore();}
<COMMENT>.                      {yymore();}

Let me know if it works.
Regards,
Nicolas

ps: I think you have to add %option stack option for yy_push_state() and yy_pop_state() to work.

James Yu wrote:
Dear all,

I am trying to define a rule for recognizing a multiple line comment in C, but I have not yet sueccessed.
Thus, I am posting my lex segment to this email and hope you can point out some mistakes for me.

== flex code segment ==
slash        "/"
asterisk    "*"
comment  ({slash}{asterisk}+([^*]|[\n])*{asterisk}+{slash})
== flex code segment ==

Any help would be gratefully appreciated,
James

_______________________________________________ Help-flex mailing list address@hidden http://lists.gnu.org/mailman/listinfo/help-flex


reply via email to

[Prev in Thread] Current Thread [Next in Thread]