Re: Flex and EOF

"Ira Baxter" <>
12 Apr 2006 22:44:59 -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: "Ira Baxter" <>
Newsgroups: comp.compilers
Date: 12 Apr 2006 22:44:59 -0400
References: 06-04-035 06-04-073
Keywords: lex
Posted-Date: 12 Apr 2006 22:44:59 EDT

"Hans-Peter Diettrich" <> wrote in message
> 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. >

Yes, the standard requires it. But, it isn't enforced. Almost all
the C/C++ compilers we encounter (e.g., have a dialect to process that
compiler source code) allow the preprocessor directive to simply end,
without a newline, commonly seen in the standard "don't include me
twice" idiom as follows:

      #ifndef foo
      #def foo
        ...<foo.h content>..

Many other languages appear to require complete lines in the abstract.
Almost none of the implementations seem to do so. For some langauges,
you actually have to preserve the fact that the last line does NOT
have a newline. (PHP is a particularly egregious example of this).


Ira Baxter, CTO

Post a followup to this message

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