Re: How do I match empty lines with Flex?

Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid>
Sat, 5 Oct 2019 22:29:46 +0800

          From comp.compilers

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)
| List of all articles for this month |
From: Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid>
Newsgroups: comp.compilers
Date: Sat, 5 Oct 2019 22:29:46 +0800
Organization: Easynews - www.easynews.com
References: 19-10-003 19-10-004
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="39815"; mail-complaints-to="abuse@iecc.com"
Keywords: flex, comment
Posted-Date: 05 Oct 2019 10:49:00 EDT
In-Reply-To: 19-10-004
Content-Language: en-GB

On 05/10/2019 12:55 am, Kaz Kylheku wrote:
> On 2019-10-04, Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote:
>> 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?
>
> How about:
>
> .+\n { num_lines++; return NONEMPTY_LINE; }
> \n { num_lines++; return EMPTY_LINE; }
> .+ { num_lines++; return MISSING_LAST_NEWLINE; }


Thank you, that indeed does the trick. With %option yylineno the count
is off by one; the first line is numbered 2 for some reason. With my
own count, it's correct.


--
Johann | email: invalid -> com | www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | twitter: @myrkraverk
[Flex starts yylineno at 1, so if you increment it in the pattern
that matches .+\n you'll see the first line as line 2. -John]


Post a followup to this message

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