Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #2373
| From | Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | How do I match empty lines with Flex? |
| Date | 2019-10-04 22:01 +0800 |
| Organization | Easynews - www.easynews.com |
| Message-ID | <19-10-003@comp.compilers> (permalink) |
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 | Next — Next in thread | Find similar
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