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 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> 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 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 char *yylval; %} %% ..* { yylval = yytext; return 1; } \n { yylineno += 1; } <> { 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]