Re: Flex and EOF

Matteo Corti <matteo.corti@gmail.com>
12 Apr 2006 22:44:31 -0400

          From comp.compilers

Related articles
Flex and EOF matteo.corti@gmail.com (Matteo Corti) (2006-04-08)
Re: Flex and EOF cdodd@acm.org (Chris Dodd) (2006-04-09)
Re: Flex and EOF rsc@swtch.com (Russ Cox) (2006-04-09)
Re: Flex and EOF tmk@netvision.net.il (Michael Tiomkin) (2006-04-09)
Re: Flex and EOF DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2006-04-10)
Re: Flex and EOF matteo.corti@gmail.com (Matteo Corti) (2006-04-12)
Re: Flex and EOF idbaxter@semdesigns.com (Ira Baxter) (2006-04-12)
| List of all articles for this month |
From: Matteo Corti <matteo.corti@gmail.com>
Newsgroups: comp.compilers
Date: 12 Apr 2006 22:44:31 -0400
Organization: ETH Zurich
References: 06-04-035 06-04-073
Keywords: lex
Posted-Date: 12 Apr 2006 22:44:31 EDT

On 2006-04-10, Hans-Peter Diettrich <DrDiettrich@compuserve.de> wrote:
> Matteo Corti wrote:
>
>> I have a rule in my lexer to skip shell-like comments:
>>
>> #.*$ /* skip comments */
>>
>> which works just fine if there is \n at the end of the line.
>> If the comment is in the last line wich is terminated by EOF the rule
>> obviously fails.
>
> This is one of the reasons why e.g. C syntax (of the preprocessor)
> requires that source files must end with a newline character. Do you
> have full control of your syntax?


Thanks for the many suggestions. I don't have *any* control on the
syntax :-) but in any case I realized that instead of being stubborn
and insist on finding a regexp I could be less lazy and write a couple
of lines of code:


"#" { /* ignore comment */


                                                      register int c;
while ((c = input()) != '\n' &&
(c != '\r') &&
                                                                    (c != EOF))
;


                                                  }


I could also, as suggested by someone, use a new state but since I already
have a couple of them for other reasons this would complicate the scanner
readability.


In any case thanks for the useful suggestions.


Matteo


--
Matteo Corti
ETH Zurich


Post a followup to this message

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