Related articles |
---|
How do I match empty lines with Flex? johann@myrkraverk.invalid (Johann 'Myrkraverk' Oskarsson) (2019-10-04) |
Re: How do I match empty lines with Flex? 847-115-0292@kylheku.com (Kaz Kylheku) (2019-10-04) |
Re: How do I match empty lines with Flex? johann@myrkraverk.invalid (Johann 'Myrkraverk' Oskarsson) (2019-10-05) |
From: | Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> |
Newsgroups: | comp.compilers |
Date: | Fri, 4 Oct 2019 22:01:48 +0800 |
Organization: | Easynews - www.easynews.com |
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 |
Content-Language: | en-GB |
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]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.