flex reg exp help

Russ Ramsey <rr61335@goodnet.com>
1 Jun 2000 17:58:34 -0400

          From comp.compilers

Related articles
flex reg exp help rr61335@goodnet.com (Russ Ramsey) (2000-06-01)
Re: flex reg exp help rr61335@goodnet.com (Russ Ramsey) (2000-06-03)
| List of all articles for this month |
From: Russ Ramsey <rr61335@goodnet.com>
Newsgroups: comp.compilers
Date: 1 Jun 2000 17:58:34 -0400
Organization: WinStar GoodNet, Inc.
Keywords: lex, comment

I am having trouble trying to parse SAS comments. Most of them are
successfully matched by the following expressions:


%{
#include "y.tab.h"
%}
%x LCOMMENT
%%
^[*].*";"[ \t]*\n { /* Self contained comment. */ }
^[ \t]+"*".*";"[ \t]*\n { }/* Self contained with leading
space. */
^[*] { BEGIN LCOMMENT; } /*
Multiline comment. */
^[* \t]+"*" { BEGIN LCOMMENT; } /* Multi
w/lead space */


<LCOMMENT>";"[ \t]*\n { BEGIN 0; } /* End of multiline comment.*/
<LCOMMENT>\n { } /* New line. */
<LCOMMENT>. { } /* Anything else. */
^[ \t\n]+ { } /* Blank Lines */
"*" { return MULTIPLICATIVE_OP }
"**" { return EXPONENTIAL_OP }
.. { }/* Anything else. */
%%


This parses the following SAS code successfully:


***************************************;
***************************************;
* INPUT VARIABLE DEFINITIONS ;
***************************************;
***************************************;
*
;
* NAME TIME PERIOD DESCRIPTION ;
*--------------------------------------------------;
* MDAIY 12 MONTHS Mail recvd ;
*
;


But the next line returns an EXPONENTAL_OP.


    *********************************;
    * VARIABLE TRANSFORMATIONS *;
    *********************************;
  The last two lines above correctly match to comments.
Why does a leading space throw off only the first comment line?
Much appreciation for any suggestions. Thanks for the book J.R.L.
Russ Ramsey
[Your question would be easier to answer if you explained what the
syntax for these comments is supposed to be, and how you can tell a
star that starts a comment from a multiplication operator. -John]





Post a followup to this message

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