C 词法语法

令牌

token:
keyword
identifier
constant
string-literal
punctuator

preprocessing-token:
header-name
identifier
pp-number
character-constant
string-literal
punctuator
 不能成为上述项目之一的每个非空白字符

关键字

keyword:以下项之一
auto break case char const continue
default do double else enum extern
float for goto if inline int long
register restrict return short signed
sizeof static struct switch typedef union
unsigned void volatile while _Alignas
_Alignof _Atomic _Bool _Complex _Generic
_Imaginary _Noreturn _Static_assert
_Thread_local

有关其他 Microsoft 专用的关键字的列表,请参阅 C 关键字

标识符

identifier:
identifier-nondigit
identifier identifier-nondigit
identifier digit

identifier-nondigit:
nondigit
universal-character-name
 其他实现定义的字符

nondigit:以下项之一
_ 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:以下项之一
0 1 2 3 4 5 6 7 8 9

universal-character-name:
\u hex-quad
\U hex-quad hex-quad

hex-quad:
hexadecimal-digit hexadecimal-digit hexadecimal-digit hexadecimal-digit

常量

constant:
integer-constant
floating-constant
enumeration-constant
character-constant

integer-constant:
decimal-constantinteger-suffixopt
binary-constant1integer-suffixopt
octal-constantinteger-suffixopt
hexadecimal-constantinteger-suffixopt

decimal-constant:
nonzero-digit
decimal-constant digit

binary-constant1
binary-prefix binary-digit
binary-constant binary-digit

binary-prefix1:以下项之一
0b 0B

binary-digit1:以下项之一
0 1

octal-constant:
0
octal-constant octal-digit

hexadecimal-constant:
hexadecimal-prefix hexadecimal-digit
hexadecimal-constant hexadecimal-digit

hexadecimal-prefix:以下项之一
0x 0X

nonzero-digit:以下项之一
1 2 3 4 5 6 7 8 9

octal-digit:以下项之一
0 1 2 3 4 5 6 7

hexadecimal-digit:以下项之一
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-suffixlong-suffixopt
unsigned-suffixlong-long-suffixopt
long-suffixunsigned-suffixopt
long-long-suffixunsigned-suffixopt

unsigned-suffix:以下项之一
u U

long-suffix:以下项之一
l L

long-long-suffix:以下项之一
ll LL

floating-constant:
decimal-floating-constant
hexadecimal-floating-constant

decimal-floating-constant:
fractional-constantexponent-partoptfloating-suffixopt
digit-sequenceexponent-partfloating-suffixopt

hexadecimal-floating-constant:
hexadecimal-prefixhexadecimal-fractional-constantbinary-exponent-partoptfloating-suffixopt
hexadecimal-prefixhexadecimal-digit-sequencebinary-exponent-partfloating-suffixopt

fractional-constant:
digit-sequenceopt.digit-sequence
digit-sequence .

exponent-part:
esignoptdigit-sequence
Esignoptdigit-sequence

sign:以下项之一
+ -

digit-sequence:
digit
digit-sequence digit

hexadecimal-fractional-constant:
hexadecimal-digit-sequenceopt.hexadecimal-digit-sequence
hexadecimal-digit-sequence .

binary-exponent-part:
psignoptdigit-sequence
Psignoptdigit-sequence

hexadecimal-digit-sequence:
hexadecimal-digit
hexadecimal-digit-sequence hexadecimal-digit

floating-suffix:以下项之一
f l F L

enumeration-constant:
identifier

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

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

c-char:
 除单引号 (')、反斜杠 (\) 或者换行符以外的所有源字符集成员
escape-sequence

escape-sequence:
simple-escape-sequence
octal-escape-sequence
hexadecimal-escape-sequence
universal-character-name

simple-escape-sequence:以下项之一
\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

字符串文本

string-literal:
encoding-prefix"s-char-sequenceopt"

encoding-prefix:
u8
u
U
L

s-char-sequence:
s-char
s-char-sequence s-char

s-char:
 除双引号 (")、反斜杠 (\) 或者换行符以外的任何源字符集成员
escape-sequence

标点符号

punctuator:以下项之一
[ ] ( ) { } . ->
++ -- & * + - ~ !
/ % << >> < > <= >= ==
!= ^ | && || ? : ; ...
= *= /= %= += -= <<= >>=
&= ^= |= , # ##
<: :> <% %> %: %:%:

标头名称

header-name:
< h-char-sequence >
" q-char-sequence "

h-char-sequence:
h-char
h-char-sequence h-char

h-char:
 除换行符和 > 以外的任何源字符集成员

q-char-sequence:
q-char
q-char-sequence q-char

q-char:
 除换行符和 " 以外的任何源字符集成员

预处理数字

pp-number:
digit
. digit
pp-number digit
pp-number identifier-nondigit
pp-number e sign
pp-number E sign
pp-number p sign
pp-number P sign
pp-number .

1binary-constantbinary-prefixbinary-digit 是 Microsoft 专用的扩展。

请参阅

C 语言语法摘要