Re: Flex and EOF

"Ira Baxter" <idbaxter@semdesigns.com>
12 Apr 2006 22:44:59 -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: "Ira Baxter" <idbaxter@semdesigns.com>
Newsgroups: comp.compilers
Date: 12 Apr 2006 22:44:59 -0400
Organization: http://extra.newsguy.com
References: 06-04-035 06-04-073
Keywords: lex
Posted-Date: 12 Apr 2006 22:44:59 EDT

"Hans-Peter Diettrich" <DrDiettrich@compuserve.de> 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>..
      #endif<EOF>


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).


Grrr.


--
Ira Baxter, CTO
www.semanticdesigns.com


Post a followup to this message

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