Re: ANSI C PreProcessor (Nick Maclaren)
5 Jan 2002 01:40:42 -0500

          From comp.compilers

Related articles
ANSI C PreProcessor (2002-01-03)
Re: ANSI C PreProcessor (Ben Pfaff) (2002-01-04)
Re: ANSI C PreProcessor (2002-01-05)
| List of all articles for this month |

From: (Nick Maclaren)
Newsgroups: comp.lang.c,comp.compilers,comp.lang.c++
Date: 5 Jan 2002 01:40:42 -0500
Organization: University of Cambridge, England
References: 02-01-013 02-01-021
Keywords: C
Posted-Date: 05 Jan 2002 01:40:42 EST

Ben Pfaff <> wrote:
> (yuval) writes:
>> Now I am in the grammar part. I want to get a BNF grammar for the C
>> PreProcessor.
>There is a grammar for the C preprocessor in the C standard.
>Google for n869 to get a C99 draft.

I suppose that I need to say that the drafts were published solely for
the purpose of public comment and may not be reproduced ad lib.
Whether your posting is a breach of the USA's chauvististic DMCA, I
don't know - but it could be, because the DMCA is that bad.

However, let's get technical. The first point is that there are at
least THREE grammars in the C standard, which use THREE different
rules for the resolution of ambiguities. And none are BNF, as such,
though none are VERY different. All use the same notation, but which
rules should be used depend on context.

Confusions in this area have led to significant incompatibilities
between implementations, many heated debates about what the standard
says, and quite significant changes between C90 and C99. In the area
of the preprocessor, the languages are different, though the
differences affect only known problem areas - as far as I know.
Examples of such areas include (but are not limited to):

        The handling of white space, especially at end of line
        What is and is not allowed in a header name
        The handling of things like '# fred' or '# pragma A " B '

What is really important to note when writing such a preprocessor is
that it is ESSENTIAL not to assume that the grammar means what it
appears to mean at first glance. Often it doesn't, and quite often
there is no explicit specification of what it does mean in the
standard itself. So take care.

Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Tel.: +44 1223 334761 Fax: +44 1223 334679
[The paper version of the C99 standard costs a fortune, but you can
buy a PDF copy from ANSI at
Click to the (default) NCITS category, then scroll down to
"ANSI/ISO/IEC 9899-1999" near the bottom of the page. It costs
$18 which is pretty reasonable for a 554 page document. ANSI gets
most of its revenue from sales of standards, if you think it's worth
having a C standard, pay the $18. -John]

Post a followup to this message

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