IS01EC14882:2011(E [Eranuple:The program fragment x+++++y is parsed as x+++++y,which,if x and y have integral types, violates a constraint on increment operators,even thongh the parse x++y might yield a correct expression.一end erample 2.6 Alternative tokens [lex.digraph] 1 Alternative token represemtations are promided for some operators and punctustors. 2 In all respects of the language,ench alternative token behaves the same,respectively,as its primary tokem, except for its spelling The se of alternative tokens is defined in Table 2. Table 2-Alternative tokens Alternative Primary Alternative Primary Alternative PT国y < and and_eg bitor 0r-09 ▣ or xor_oq “。 4> XOF BOt : compl notoq ■7 :X知 单世 bitand 2.7 Tokens lex.token] token: idendifier eryond fitersd operater punctator 1 There are five kinds of tobens identifiers.keywords,literals,Is operntors,and other separators.Blanks, horizontal and vertical tahs,newlines formfoods,and comments (collectively,"white space"),as deseribed belw,are ignored except as they serve to separate tobens.Note:Some white space is required to sepa rate otherutse ad aceat Ideatifiers,keywords,mmeric literals,and alternative tolens comtaining alphabetle characters一cnan对o 2.8 Comments lex.comment 1 The characters /start a comment,which terminates with the characters /These comments do not neet.The characters /start a comment.which terminatess with the next new-line character.If there is a form-feed or a vertical-tab charncter in such a comment,only white-space characters shall appear betwen it and the niw-line that terminates the commet:no diagnoetic is rquired.Node:The comment characters 16)These inclade "digraphs"and additional rewerved woeds.The term"digraph"(tolen coasiting cd two characters)ie noe perfoctly descriptive.sice oue of the altemative prepeecessing-loketrs is :and of course severel primezy toketrs comtain two character.Nonetheles those altermative tolera that aren't lexical krywurds are colloqulally knom as "digraph". I7)Tte“igio了ales6从2)gd【al<1 will be difeeen瑞,aintaining the source spe酒nEbd1eoes otherwise be freely interchangrd. Ls身nerals include城r也停adh过er and trumeric litemb 52.8 ●G0MEC2011-Al nights teserved 21
5 [Example: The program fragment x+++++y is parsed as x ++ ++ + y, which, if x and y have integral types, violates a constraint on increment operators, even though the parse x ++ + ++ y might yield a correct expression. — end example ] 2.6 Alternative tokens [lex.digraph] 1 Alternative token representations are provided for some operators and punctuators.16 2 In all respects of the language, each alternative token behaves the same, respectively, as its primary token, except for its spelling.17 The set of alternative tokens is defined in Table 2. Table 2 — Alternative tokens Alternative Primary Alternative Primary Alternative Primary <% { and && and_eq &= %> } bitor | or_eq |= <: [ or || xor_eq ˆ= :> ] xor ˆ not ! %: # compl ∼ not_eq != %:%: ## bitand & 2.7 Tokens [lex.token] token: identifier keyword literal operator punctuator 1 There are five kinds of tokens: identifiers, keywords, literals,18 operators, and other separators. Blanks, horizontal and vertical tabs, newlines, formfeeds, and comments (collectively, “white space”), as described below, are ignored except as they serve to separate tokens. [ Note: Some white space is required to separate otherwise adjacent identifiers, keywords, numeric literals, and alternative tokens containing alphabetic characters. — end note ] 2.8 Comments [lex.comment] 1 The characters /* start a comment, which terminates with the characters */. These comments do not nest. The characters // start a comment, which terminates with the next new-line character. If there is a form-feed or a vertical-tab character in such a comment, only white-space characters shall appear between it and the new-line that terminates the comment; no diagnostic is required. [ Note: The comment characters 16) These include “digraphs” and additional reserved words. The term “digraph” (token consisting of two characters) is not perfectly descriptive, since one of the alternative preprocessing-tokens is %:%: and of course several primary tokens contain two characters. Nonetheless, those alternative tokens that aren’t lexical keywords are colloquially known as “digraphs”. 17) Thus the “stringized” values (16.3.2) of [ and <: will be different, maintaining the source spelling, but the tokens can otherwise be freely interchanged. 18) Literals include strings and character and numeric literals. § 2.8 ISO/IEC 14882:2011(E) © ISO/IEC 2011 – All rights reserved 21
1S0/1EC14882:2011(但) ///.and/have no special meaning within a /comment and are treated just like other characters. Similarly,the comment characters /and /have no special meaning within a comment.-end note] 2.9 Header names llex.header hm山下uwn 《h-har-segwrnor ”ste■ h-char. hecbar h-clar-semesce A-char hechor: any member of the source character set except new-line and g-char-seyuece: o-char o-char-sequenee gchar char: any member of the souree character sat ext new-line and 1 Header mame preprocessing tokens shall only appear within a #inlude preprocesesing directive(16.2).The seruences in both forms of hender-nemes are mapped in an implmemtation-defined manner to beaders or to extermal source file names as specified in 16.2. 2 The appearance of either of the charneters or or of either of the character soquences or /in a char-somuence or an h-char-sequence is cooditionally supported with implementatioe-defined semantics.as the appeurance of the charactern an hchar-sewence 2.10 Preprocessing numbers [lex.ppnumber] pp-mnler: digil gt pp-namber digit pp-namber idesliier-nondigil Pp-nam行专n pp-nambr E xign pp-namber. 1 Preprocessing mumber tokens lexicnlly include all integral literal tokens (2.14.2)and all floating lteral to. kas(2,14,4 2 A preproceseing mmber does not hae a type or a vale:it acquires both after a suocessful comvenion to an integral literal toke oe n floating lternl token. 2.11 Identifiers lex.name identlfier: idralifier-nondigit w0的er ideatilerondigit identier digit identiGer-ouoodigit: nondigil anieersalclarecfername cher implematice-defined characters 19)Thus,a sequence of that resembdes an eseape sequence might result in an error.be interpeeted as the charactee coreponding to the ecape soquaence,or have a coepktely cierent meaning,dopeading on the implementation. s211 22 DISOEC 2011 -Al rghts reervd
//, /*, and */ have no special meaning within a // comment and are treated just like other characters. Similarly, the comment characters // and /* have no special meaning within a /* comment. — end note ] 2.9 Header names [lex.header] header-name: < h-char-sequence > " q-char-sequence " h-char-sequence: h-char h-char-sequence h-char h-char: any member of the source character set except new-line and > q-char-sequence: q-char q-char-sequence q-char q-char: any member of the source character set except new-line and " 1 Header name preprocessing tokens shall only appear within a #include preprocessing directive (16.2). The sequences in both forms of header-names are mapped in an implementation-defined manner to headers or to external source file names as specified in 16.2. 2 The appearance of either of the characters ’ or \ or of either of the character sequences /* or // in a q-char-sequence or an h-char-sequence is conditionally supported with implementation-defined semantics, as is the appearance of the character " in an h-char-sequence. 19 2.10 Preprocessing numbers [lex.ppnumber] pp-number: digit . digit pp-number digit pp-number identifier-nondigit pp-number e sign pp-number E sign pp-number . 1 Preprocessing number tokens lexically include all integral literal tokens (2.14.2) and all floating literal tokens (2.14.4). 2 A preprocessing number does not have a type or a value; it acquires both after a successful conversion to an integral literal token or a floating literal token. 2.11 Identifiers [lex.name] identifier: identifier-nondigit identifier identifier-nondigit identifier digit identifier-nondigit: nondigit universal-character-name other implementation-defined characters 19) Thus, a sequence of characters that resembles an escape sequence might result in an error, be interpreted as the character corresponding to the escape sequence, or have a completely different meaning, depending on the implementation. § 2.11 ISO/IEC 14882:2011(E) 22 © ISO/IEC 2011 – All rights reserved
1s0MEC14882:2011(E mondigit:one of ab e d e f g h i j k l 五0P9x日tut¥xy2 A B C D E F C H I J K L H 超0P日a8TUt¥xr2 d的oeod 0123456789 1 An idemtifier is an arbitrarily long squence of letters and digits.Each tniversal-character-mame in an idemtifier shall designate a character whoee encoding in ISO 10616 fall into one of the ranges specified in E.1.The initial eement shall not be a universal-charneter-name designating a character whooe encoding falls into ooe of the ranges specified in E.2.Upper-and lower-case letters are different.All characters are signlfeant.20 2 The identifiers in Table 3 hmve a special meaning when appearing in a certain context.When referred to in the grammar,tbese identifers are used explicitly rather than using the identifier grammar prodoction. amy amhiguity as to whether a given iderifier has a special meaning is rsolved to interpret the token as a regular identifer. Table 3-Identifiers with special meaning override fimal 8 In addition.some idemtifiers are reserved for use by C++implementations and standard libraries (17.6.4.3.2) and shall pot be used otherwises no diagnostle is roquired. 2.12 Keywords lex.key] 1 The identifers shown in Table 4 are reserved for use as keywords (that b,they are unconditionally treatod as keywords in phase 7)except in an stribate-toirm (7.6.1)Note:The export keyword is ummsed bat is reserved for future use.-end note: Tala4一K4ardw a11知a8 continue friend register true alignof decltype goto reintorpretcast y a球 default return typedef auto delete imline short typeid bool de Ist algned typesane break double 10g 81z60f unicm C90 4色a1C.cast Btable static unsigsed catch 中1表特 BAn特8PAC形 8tat1G_a8*物r七 using char 兰a 日W atatic_cast virtual charl6_t explicit noexcept Btroct void char32t xPOrE aullptr avitch volatila G1588 extern operator template wchar_t const false private this while constexpr f10w无 protected thrend_local const_cast for pablic throw 2时On systems鱼which linkers camnot accept e3eeaf线ane0 g of the universaleharacter-ame may be in fonning wlid exctemal idemtifiers.Foe exsample.some etherwrise snused character er seqence of chancters may be ssed to encode the Ve in a tiveral-character-uame.Extended chamclers may peoduce a lag external idertifer,but C++does not place a traalation limit on signifcant chararteas foe excternal identifees.In C4+.spper.and lomercase ktters are conaidered different for all iderifers,incdading exermal kentiers. s2.12 SOMEC 2011 -All rights seserved 23
nondigit: one of a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ digit: one of 0 1 2 3 4 5 6 7 8 9 1 An identifier is an arbitrarily long sequence of letters and digits. Each universal-character-name in an identifier shall designate a character whose encoding in ISO 10646 falls into one of the ranges specified in E.1. The initial element shall not be a universal-character-name designating a character whose encoding falls into one of the ranges specified in E.2. Upper- and lower-case letters are different. All characters are significant.20 2 The identifiers in Table 3 have a special meaning when appearing in a certain context. When referred to in the grammar, these identifiers are used explicitly rather than using the identifier grammar production. any ambiguity as to whether a given identifier has a special meaning is resolved to interpret the token as a regular identifier. Table 3 — Identifiers with special meaning override final 3 In addition, some identifiers are reserved for use by C++ implementations and standard libraries (17.6.4.3.2) and shall not be used otherwise; no diagnostic is required. 2.12 Keywords [lex.key] 1 The identifiers shown in Table 4 are reserved for use as keywords (that is, they are unconditionally treated as keywords in phase 7) except in an attribute-token (7.6.1) [ Note: The export keyword is unused but is reserved for future use.— end note ]: Table 4 — Keywords alignas continue friend register true alignof decltype goto reinterpret_cast try asm default if return typedef auto delete inline short typeid bool do int signed typename break double long sizeof union case dynamic_cast mutable static unsigned catch else namespace static_assert using char enum new static_cast virtual char16_t explicit noexcept struct void char32_t export nullptr switch volatile class extern operator template wchar_t const false private this while constexpr float protected thread_local const_cast for public throw 20) On systems in which linkers cannot accept extended characters, an encoding of the universal-character-name may be used in forming valid external identifiers. For example, some otherwise unused character or sequence of characters may be used to encode the \u in a universal-character-name. Extended characters may produce a long external identifier, but C++ does not place a translation limit on significant characters for external identifiers. In C++, upper- and lower-case letters are considered different for all identifiers, including external identifiers. § 2.12 ISO/IEC 14882:2011(E) © ISO/IEC 2011 – All rights reserved 23
1S0/1EC14882:2011(目) 2 Furthermore,the alternative repeesentations shown in Table 5 foe certaln operators and punctuators (2.fi) are reserved and shall not be used otherwise Table 5-Alternative representations and and_eq bitand bitor compl not not_eg or 0r-.的or xor_eq 2.13 Operators and punctuators [lex.operators] 1 The lexical repreentation of C++programs includes a number of preprocessing tokens which are used in the symtax of the preproceseor or are comverted into tokens Bor operators and pumctuators: pmpop-6-pine:ome of 《 ◆ 单果 X:4: wda1wt自7 1- 业= >>m ->4 -2 asd andeq bitasd bitor compl not a06_.9q or ar_aq zar xoT_nq Each preprocessing-op-or-pane is comertod to a single token n translation phase 7 (2.2). 2.14 Literals [lex.literal] 2.14.1 Kinds of literals lex.literal.kinds 1 There are several kinds of literals 21 eral. indeger-litersl character-literd 是sn小esd s白ing-ieml boofean-erul podnder-hiternl naer-defined-literal 2.14.2 Integer literals flex.icon] intrer-lilerul: decimal-lteral iuteger历a octal-lteral indrger.历 heradecimal-literaf integers decitusl-literal: nonzero-digit decimal-Miteral digit octal-hiteral 0 ocfal.Miteral octaldigit 2)The ter“tea了erally designates,nths1 ternational Stasdand.th6 e tokens th解te caled "constants”nSOC 52.142 24 ●50EC2011=Al rights reserved
2 Furthermore, the alternative representations shown in Table 5 for certain operators and punctuators (2.6) are reserved and shall not be used otherwise: Table 5 — Alternative representations and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq 2.13 Operators and punctuators [lex.operators] 1 The lexical representation of C++ programs includes a number of preprocessing tokens which are used in the syntax of the preprocessor or are converted into tokens for operators and punctuators: preprocessing-op-or-punc: one of { } [ ] # ## ( ) <: :> <% %> %: %:%: ; : ... new delete ? :: . .* + - * / % ˆ & | ~ ! = < > += -= *= /= %= ˆ= &= |= << >> >>= <<= == != <= >= && || ++ -- , ->* -> and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq Each preprocessing-op-or-punc is converted to a single token in translation phase 7 (2.2). 2.14 Literals [lex.literal] 2.14.1 Kinds of literals [lex.literal.kinds] 1 There are several kinds of literals.21 literal: integer-literal character-literal floating-literal string-literal boolean-literal pointer-literal user-defined-literal 2.14.2 Integer literals [lex.icon] integer-literal: decimal-literal integer-suffixopt octal-literal integer-suffixopt hexadecimal-literal integer-suffixopt decimal-literal: nonzero-digit decimal-literal digit octal-literal: 0 octal-literal octal-digit 21) The term “literal” generally designates, in this International Standard, those tokens that are called “constants” in ISO C. § 2.14.2 ISO/IEC 14882:2011(E) 24 © ISO/IEC 2011 – All rights reserved
Is0MEC14882:2011(但 herodecimel-literal: Oz heradrcivual-点i O heradecivoal-digit heraderival-literl hezedecimel-digit nongem-digit:one of 123456789 octadigit:one of 01294567 herodecimel-diglt:one of 0123456789 a b c d e A B C D E F ily-乐 sigued-muffr long-su时 ng西dng-lo学s, on今u行ng四k作红时 ong-long.sn证asigned.stfir, nime.o压one of n U lonu作ue6d I L ang-a学历ce of 11 LL 1 An futeger iteral is a soquence of digits that has no period or exponent part.An integer literal may have a prefix that specifies its base and a suffix that specifies its type.The lexically first digit of the sequenoe of digits is the moet significant.A decimal integer literal (base ten)begins with a digit other than 0 and consists of a sequemee of decimal digits.An ocfal integer literal (base eight)bgins with the digit 0 anl consists of a sequence of octal digits.A heradecimal integer literal (base sixteen)begins with x or 0x and consists of a soquenee of hexcadeeimal digits,whlch lnelude the doclmal digits and the ktters a through f and A through F with decimal values ten through fifteen.Erample:the mmber twelve can be written 12. 014,60C,一dum 2 The type of an integer literal is the first of the corresponding list in Table 6 in which its vuhe ean be represented. Table 6-Types of integer constants Sullix Deeimal constants Detal or hexadecimal con为twn时 none int 1ong1■t unsigned int long long int long int tn移1gned1ong1mt long long int unaigned long long int u oe U unsigned int unsigned int ns1知ed1ong1■t unsigned long int unsigned long long int unsigned long long int 1 or L long int long int longlong int unsigned long ist leng long int unsigned long long int 22)The digits 8 and 9 are not ectal digits. 5214.2 DSOMEC 2011 -Al rights teserwd 25
hexadecimal-literal: 0x hexadecimal-digit 0X hexadecimal-digit hexadecimal-literal hexadecimal-digit nonzero-digit: one of 1 2 3 4 5 6 7 8 9 octal-digit: one of 0 1 2 3 4 5 6 7 hexadecimal-digit: one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F integer-suffix: unsigned-suffix long-suffixopt unsigned-suffix long-long-suffixopt long-suffix unsigned-suffixopt long-long-suffix unsigned-suffixopt unsigned-suffix: one of u U long-suffix: one of l L long-long-suffix: one of ll LL 1 An integer literal is a sequence of digits that has no period or exponent part. An integer literal may have a prefix that specifies its base and a suffix that specifies its type. The lexically first digit of the sequence of digits is the most significant. A decimal integer literal (base ten) begins with a digit other than 0 and consists of a sequence of decimal digits. An octal integer literal (base eight) begins with the digit 0 and consists of a sequence of octal digits.22 A hexadecimal integer literal (base sixteen) begins with 0x or 0X and consists of a sequence of hexadecimal digits, which include the decimal digits and the letters a through f and A through F with decimal values ten through fifteen. [Example: the number twelve can be written 12, 014, or 0XC. — end example ] 2 The type of an integer literal is the first of the corresponding list in Table 6 in which its value can be represented. Table 6 — Types of integer constants Suffix Decimal constants Octal or hexadecimal constant none int int long int unsigned int long long int long int unsigned long int long long int unsigned long long int u or U unsigned int unsigned int unsigned long int unsigned long int unsigned long long int unsigned long long int l or L long int long int long long int unsigned long int long long int unsigned long long int 22) The digits 8 and 9 are not octal digits. § 2.14.2 ISO/IEC 14882:2011(E) © ISO/IEC 2011 – All rights reserved 25