Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #2373

How do I match empty lines with Flex?

Path csiph.com!3.us.feeder.erje.net!feeder.erje.net!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid>
Newsgroups comp.compilers
Subject How do I match empty lines with Flex?
Date Fri, 4 Oct 2019 22:01:48 +0800
Organization Easynews - www.easynews.com
Lines 45
Sender news@iecc.com
Approved comp.compilers@iecc.com
Message-ID <19-10-003@comp.compilers> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
Injection-Info gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="21086"; mail-complaints-to="abuse@iecc.com"
Keywords lex, question, comment
Posted-Date 04 Oct 2019 11:29:50 EDT
X-submission-address compilers@iecc.com
X-moderator-address compilers-request@iecc.com
X-FAQ-and-archives http://compilers.iecc.com
Content-Language en-GB
Xref csiph.com comp.compilers:2373

Show key headers only | View raw


Dear comp.compilers,

The following program matches lines in a text file, but ignores empty
lines.  Is there any way I can alter it so it returns something on empty
lines?

Is there a reason .* doesn't match zero characters in this case?

%option noyywrap noinput nounput

%{
#include <stdio.h>

     char *yylval;

%}


%%

..* { yylval = yytext; return 1; }
\n { yylineno += 1; }
<<EOF>> { return 0; }

%%

int main( int argc, char *argv[] )
{
     if ( argc > 1 ) {
         yyin = fopen( argv[ 1 ], "r" );

         while ( yylex() ) {
             printf( "%d: %s\n", yylineno, yylval );

         }
     }

     return 0;
}

--
Johann | email: invalid -> com | www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | twitter: @myrkraverk
[Flex never matches an empty string.
I expect a pattern like ^\n would do what you want. -John]

Back to comp.compilers | Previous | NextNext in thread | Find similar


Thread

How do I match empty lines with Flex? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2019-10-04 22:01 +0800
  Re: How do I match empty lines with Flex? Kaz Kylheku <847-115-0292@kylheku.com> - 2019-10-04 16:55 +0000
    Re: How do I match empty lines with Flex? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2019-10-05 22:29 +0800

csiph-web