Re: Flex and EOF

Matteo Corti <>
12 Apr 2006 22:44:31 -0400

          From comp.compilers

Related articles
Flex and EOF (Matteo Corti) (2006-04-08)
Re: Flex and EOF (Chris Dodd) (2006-04-09)
Re: Flex and EOF (Russ Cox) (2006-04-09)
Re: Flex and EOF (Michael Tiomkin) (2006-04-09)
Re: Flex and EOF (Hans-Peter Diettrich) (2006-04-10)
Re: Flex and EOF (Matteo Corti) (2006-04-12)
Re: Flex and EOF (Ira Baxter) (2006-04-12)
| List of all articles for this month |

From: Matteo Corti <>
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 <> 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

In any case thanks for the useful suggestions.


Matteo Corti
ETH Zurich

Post a followup to this message

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