Re: C scanners, was Hand written or tool generated lexical analyzers for FORTRAN

Vesa Karvonen <vesa.karvonen@cs.helsinki.fi>
13 Oct 2005 20:37:21 -0400

          From comp.compilers

Related articles
Hand written or tool generated lexical analyzers for FORTRAN pankaj.jangid@gmail.com (Pankaj) (2005-09-14)
Re: Hand written or tool generated lexical analyzers for FORTRAN fjscipio@rochester.rr.com (Fred J. Scipione) (2005-09-17)
Re: Hand written or tool generated lexical analyzers for FORTRAN pankaj.jangid@gmail.com (Pankaj) (2005-09-27)
Re: C scanners, was Hand written or tool generated lexical analyzers f rsc@swtch.com (Russ Cox) (2005-09-30)
Re: C scanners, was Hand written or tool generated lexical analyzers f nmm1@cus.cam.ac.uk (2005-10-02)
Re: C scanners, was Hand written or tool generated lexical analyzers f vesa.karvonen@cs.helsinki.fi (Vesa Karvonen) (2005-10-13)
| List of all articles for this month |

From: Vesa Karvonen <vesa.karvonen@cs.helsinki.fi>
Newsgroups: comp.compilers
Date: 13 Oct 2005 20:37:21 -0400
Organization: University of Helsinki
References: 05-09-054 05-09-069 05-09-127 05-09-137 05-10-004
Keywords: C, syntax

Nick Maclaren <nmm1@cus.cam.ac.uk> wrote:


> But, if you exclude that, and the more contorted use of the # and ##
> preprocessor operations, I believe that most C compilers do work the
> way you say. There are some truly horrible ambiguities with those
> operators, but thankfully nobody seems to use the constructions that
> trigger them.


I don't think that there are "horrible ambiquities" (at least not when
compared to the rest of the language) with the # and ## operators of
the C preprocessor. The semantics of the # and ## operators are
relatively clearly spelled out. However, based on my experience in
writing C preprocessor metaprograms, like


    http://cvs.sourceforge.net/viewcvs.py/chaos-pp/order-pp/example/bottles.c?view=markup


it seems that relatively few preprocessors implement the C
preprocessor correctly.


> #include <stddef.h>
> #define A(x) # x
> A(offsetof)


> is one of the simpler and more unambiguously implementation dependent.


Are you saying that the token sequence resulting from preprocessing
the above macro invocation


    A(offsetof)


is implementation dependent? It isn't:


                      "If, in the replacement list, a parameter is immediately
              preceded by a # preprocessing token, both are replaced by a
              single character string literal preprocessing token that
              contains the spelling of the preprocessing token sequence
              for the corresponding argument. Each occurrence of white
              space between the argument's preprocessing tokens becomes a
              single space character in the character string literal.
              White space before the first preprocessing token and after
              the last preprocessing token composing the argument is
              deleted.")


The result of the above macro invocation must be


    "offsetof"


on all C99 conforming preprocessors.


-Vesa Karvonen



Post a followup to this message

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