编程语言

img lynnboy

2.13.2 - [lex.ccon] - 【词法.字符常量】

发表于2004/10/31 18:39:00  2688人阅读

分类: ISO/IEC 14882:1998

请不要转载本文;请不要以任何形式重新出版,发布本文;请在下载本文 24 小时内将其删除;禁止将本文用于商业目的。

2 Lexical conventions [lex]

2.13 Literals [lex.literal]

2.13.2 Character literals [lex.ccon]

 

2 词法约定 【词法】

2.13 文字量 【词法.文字量】

2.13.2 字符文字量 【词法.字符常量】

 

    character-literal:
        'c-char-sequence'
        L'c-char-sequence'

    c-char-sequence:
        c-char
        c-char-sequence c-char

    c-char:
        any member of the source character set except
            the single-quote ', backslash /, or new-line character
        escape-sequence
        universal-character-name

    escape-sequence:
        simple-escape-sequence
        octal-escape-sequence
        hexadecimal-escape-sequence

    simple-escape-sequence: one of
        /' /" /? //
        /a /b /f /n /r /t /v

    octal-escape-sequence:
        / octal-digit
        / octal-digit octal-digit
        / octal-digit octal-digit octal-digit

    hexadecimal-escape-sequence:
        /x hexadecimal-digit
        hexadecimal-escape-sequence hexadecimal-digit

 

    字符-文字量:
        'c-字符-序列'
        L'c-字符-序列'

    c-字符-序列:
        c-字符
        c-字符-序列 c-字符

    c-字符:
        源字符集中的任何字符,除了
            单引号 ',反斜杠 /,或换行字符
        转义-序列
        统一字符名称

    转义-序列:
        简单-转义-序列
        八进制-转义-序列
        十六进制-转义-序列

    简单-转义-序列: 下列之一
        /' /" /? //
        /a /b /f /n /r /t /v

    八进制-转义-序列:
        / 八进制-数字
        / 八进制-数字 八进制-数字
        / 八进制-数字 八进制-数字 八进制-数字

    十六进制-转义-序列:
        /x 十六进制-数字
        十六进制-转义-序列 十六进制-数字

 

A character literal is one or more characters enclosed in single quotes, as in 'x', optionally preceded by the letter L, as in L'x'. A character literal that does not begin with L is an ordinary character literal, also referred to as a narrow-character literal. An ordinary character literal that contains a single c-char has type char, with value equal to the numerical value of the encoding of the c-char in the execution character set. An ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter literal has type int and implementation-defined value.

 

字符文字量是被单引号包围的一个或多个字符,如 'x',也可跟在字母 L 后面,如 L'x'。 前面没有 L 的字符文字量是普通字符文字量,也叫做窄字符文字量。包含单个 c-字符的普通字符文字量具有类型 char, 与执行字符集中该 c-字符的编码数值相等。包含多个 c-字符的普通字符文字量是多字符文字量。多字符文字量的类型是 int,其值由实现定义。

 

A character literal that begins with the letter L, such as L'x', is a wide-character literal. A wide-character literal has type wchar_t.23) The value of a wide-character literal containing a single c-char has value equal to the numerical value of the encoding of the c-char in the execution wide-character set. The value of a wide-character literal containing multiple c-chars is implementation-defined.

 

L 开始的字符文字量是宽字符文字量,如 L'x'。宽字符文字量具有类型 wchar_t23) 包含一个 c-字符的宽字符文字量的值与执行宽字符集中该 c-字符的编码数值相等。包含多个 c-字符的宽字符文字量的值由实现定义。

 

Certain nongraphic characters, the single quote ', the double quote ", the question mark ?, and the backslash /, can be represented according to Table 5.

Table 5 - escape sequences

new-line NL(LF) /n
horizontal tab HT /t
vertical tab VT /v
backspace BS /b
carriage return CR /r
form feed FF /f
alert BEL /a
backslash / //
question mark ? /?
single quote ' /'
double quote " /"
octal number ooo /ooo
hex number hhh /xhhh

The double quote " and the question mark ?, can be represented as themselves or by the escape sequences /" and /? respectively, but the single quote ' and the backslash / shall be represented by the escape sequences /' and // respectively. If the character following a backslash is not one of those specified, the behavior is undefined. An escape sequence specifies a single character.

 

某些非图形字符,单引号 ',双引号 ",问号 ?,以及反斜线 /,按照表格 5 来说明。

表格 5 - 转义序列

换行 NL(LF) /n
水平表格 HT /t
垂直表格 VT /v
退格 BS /b
回车 CR /r
换页 FF /f
警报 BEL /a
反斜线 / //
问号 ? /?
单引号 ' /'
双引号 " /"
八进制数值 ooo /ooo
十六进制数值 hhh /xhhh

双引号 " 和问号 ?,可以单独代表其自身,或分别用转义序列 /"/? 代表,但单引号 ' 和反斜线 / 应该由转义序列 /'// 分别代表。如果跟在反斜线后面的字符没有被指定,其行为是未定义的。一个转义序列代表单个字符。

 

The escape /ooo consists of the backslash followed by one, two, or three octal digits that are taken to specify the value of the desired character. The escape /xhhh consists of the backslash followed by x followed by one or more hexadecimal digits that are taken to specify the value of the desired character. There is no limit to the number of digits in a hexadecimal sequence. A sequence of octal or hexadecimal digits is terminated by the first character that is not an octal digit or a hexadecimal digit, respectively. The value of a character literal is implementation-defined if it falls outside of the implementation-defined range defined for char (for ordinary literals) or wchar_t (for wide literals).

 

由反斜线后面跟着一个,两个或三个八进制数字构成的转义序列 /ooo,用以代表其所指定字符的值。由反斜线后面跟着 x 再跟着一个或多个十六进制数字构成的转义序列 /xhhh,用以代表其所指定字符的值。十六进制序列的数字个数没有限制。八进制或十六进制数字序列分别在遇到第一个不是八进制或十六进制数字的字符时结束。当字符文字量的值超过由实现定义的 char(对于普通文字量)或 wchar_t(对于宽文字量)的数值范围时,其值由实现定义。

 

A universal-character-name is translated to the encoding, in the execution character set, of the character named. If there is no such encoding, the universal-character-name is translated to an implementation-defined encoding. [Note: in translation phase 1, a universal-character-name is introduced whenever an actual extended character is encountered in the source text. Therefore, all extended characters are described in terms of universal-character-names. However, the actual compiler implementation may use its own native character set, so long as the same results are obtained. ]

 

统一字符名称被翻译成其命名的字符在运行字符集中的编码。如果此编码不存在,则统一字符名称被翻译成实现定义的编码。【注:在翻译阶段 1,一旦某扩展字符在源文本中出现,统一字符名称就被引入。因此,所有扩展字符都按照统一字符名称来表示。然而,只要能够产生相同结果,实际编译器实现可以使用其自己的本地字符集。】

 

23) They are intended for character sets where a character does not fit into a single byte.

 

23) 它们由不能用单个字节表达字符的字符集利用。

 

PREV [lex.icon] | NEXT [lex.fcon] 上一页 【词法.整型常量】 | 下一页 【词法.浮点常量】
阅读全文
0 0

相关文章推荐

img
取 消
img