Identifier (annotated)

參考: https://en.cppreference.com/w/c/language/identifier

有關C99 identifier的定義

6.4.2.1 An identifier is a sequence of nondigit characters (including the underscore _, the lowercase and uppercase Latin letters, and other characters) and digits.

C99也支援universal-character-name \u or \U開頭的UCN來作為identifier的字元(可以在identifier開頭) \u接4個hex \U接8個hex

當然也考慮了上面提到的不能digit開頭的限制

Each universal character name in an identifier shall designate a character whose encoding in ISO/IEC 10646 falls into one of the ranges specified in annex D.59) The initial character shall not be a universal character name designating a digit.

6.2.1 An identifier can denote an object; a function; a tag or a member of a structure, union, or enumeration; a typedef name; a label name; a macro name; or a macro parameter

macro name也是identifier, 但在compile (phase 7)時已經沒有macro了。事實上這邊指的identifier同樣也用在preprocessing token。並且在preprocessing階段,identifier只分成macro和不是macro。 可參考 §6.10.1 140)

Because the controlling constant expression is evaluated during translation phase 4, all identifiers either are or are not macro names — there simply are no keywords, enumeration constants, etc

6.4 Lexical elements Syntax

6.4.2.1 When preprocessing tokens are converted to tokens during translation phase 7, if a preprocessing token could be converted to either a keyword or an identifier, it is converted to a keyword

這段主要是說在preprocessing token階段,沒有keyword概念(可參看上面的6.4 Lexical elements Syntax),所以tokenize時標記的會是identifier,可是到phase 7時,會轉成token,這時候就會區分要算在token的keyword還是identifier

This entry was posted in C Language. Bookmark the permalink.

Leave a Reply