ISO/ IEC JTC1/SC22/WG14 N673

                    Document Number:  WG14 N673/X3J11 97-036

                        C9X Revision Proposal
                        =====================

Title: adjustments to phases of translation
Author: Clive D.W. Feather
Author Affiliation: Demon Internet Ltd
Postal Address: 322 Regents Park Road, London N3 2QQ, UK
E-mail Address: clive@demon.net
Telephone Number: +44 181 371 1138
Fax Number: +44 181 371 1037
Date: 1997-03-03
Sponsor: BSI/WG14
Proposal Category:
   __ Editorial change/non-normative contribution
   XX Correction
   __ New feature
   __ Addition to obsolescent feature list
   __ Addition to Future Directions
   __ Other (please specify)  ______________________________
Area of Standard Affected:
   XX Environment
   XX Language
   __ Preprocessor
   __ Library
      __ Macro/typedef/tag name
      __ Function
      __ Header
   __ Other (please specify)  ______________________________
Prior Art: n/a
Target Audience: all

Related Documents (if any): none

Proposal Attached: Yes

Abstract:
This proposal makes various clarifications and corrections to the
concepts involved in the phases of translation. No new features are
added.


Notes:
This proposal was prepared with the assistance of Mark Brader, Jutta
Degener, Ron Guilmette, and a person whose employment conditions require
anonymity.


Summary
-------
This proposal makes various clarifications and corrections to the
concepts involved in the phases of translation. No new features are
added.


Conformance
-----------
No C89 strictly conforming program should be affected by this proposal.


Discussion
----------
On close examination, there appear to be a number of inconsistencies,
irregularities, and omissions in the concepts surrounding the phases of
translation. This proposal attempts to clean up some of them.

(1) The present wording of translation phase 2 implies that, after
splicing, the implementation must scan backwards one character for
another backslash where another newline occurs immediately after the
splice, and thus (for example) that three backslashes followed by three
newlines are all removed. This seems undesirable, and it is reported
that existing implementations vary in their handling of this. The
proposal makes it clear that only a backslash at the end of a *physical*
source line causes splicing.

(2) The interaction of #include and #if, where the included file
contains unbalanced #if, #else, #elif, or #endif directives, is
clarified to be a syntax violation. Without this, the effect of (say)
the directive "#elif 0" in the middle of a conditionally included file
would be non-intuitive. The simplest way to do this is to correct an
additional oversight, and make it clear what the various "start symbols"
of the grammar are and when they apply.


Detailed proposal
-----------------
[All references are taken from draft 9 pre 3.]

In subclause 5.1.1.2, replace translation phase 2 with:

  Each  instance  of a backslash character immediately
  followed by a newline character is deleted, splicing
  physical source lines to form logical  source lines.
  Only the last backslash on any physical source line
  shall be eligible for being part of such a splice. A
  source file that is not empty shall end in a new-line
  character, which shall not be immediately preceded by
  a backslash character before any such splicing takes
  place.[*]

  [*] Thus the physical source lines (delimited by | characters):
      |\\\|
      ||
      |n|
  generate the logical source lines:
      |\\|
      |n|
  and a source file may end with a backslash followed by two
  physical newlines, which will generate a last logical source
  line ending in a backslash.


Append to subclause 5.1.1.3, immediately before the example:

  A syntax rule is violated if, in translation phase 4, any source file
  or header (each file and header being considered separately, before
  the processing of any #include directives) fails to be an example of
  the syntactic category preprocessing-file or, in translation phase 7,
  the translation unit fails to be an example of the syntactic category
  translation-unit.

and add the Rationale material:

  In translation phase 4, the syntactic category preprocessing-file
  applies to each included file separately from the file it is included
  into. Thus an included file cannot contain (for example) unbalanced
  #else or #elif directives.

-- 
Clive D.W. Feather    | Associate Director  | Director
Tel: +44 181 371 1138 | Demon Internet Ltd. | CityScape Internet Services Ltd.
Fax: +44 181 371 1150 | <clive@demon.net>   | <cdwf@cityscape.co.uk>
Written on my laptop - please reply to the Reply-To address <clive@demon.net>