Path: csiph.com!xmission!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: Re: How do I match empty lines with Flex? Date: Sat, 5 Oct 2019 22:29:46 +0800 Organization: Easynews - www.easynews.com Lines: 23 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <19-10-005@comp.compilers> References: <19-10-003@comp.compilers> <19-10-004@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="39815"; mail-complaints-to="abuse@iecc.com" Keywords: flex, comment Posted-Date: 05 Oct 2019 10:49:00 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com In-Reply-To: <19-10-004@comp.compilers> Content-Language: en-GB Xref: csiph.com comp.compilers:2375 On 05/10/2019 12:55 am, Kaz Kylheku wrote: > On 2019-10-04, Johann 'Myrkraverk' Oskarsson 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]