标识符是否仅在某些情况下是单独的标记?

huangapple go评论93阅读模式
英文:

Are identifiers separate tokens only in select cases?

问题

> 1. 词法陷阱:
>
> 举个例子,考虑以下语句:

if (x < big) big = x; 

> 这个语句中的每个非空白字符都是一个单独的标记,
> 除了 if 关键字和标识符 big 的两个实例之外。
>
> 实际上,C程序会被分为两次标记...

— 来自《C陷阱与技巧》(C Traps and Pitfalls, Andrew Koenig)

英文:

> 1. Lexical Pitfalls:
>
> For another example, consider this statement:

if (x < big) big = x; 

>Each non-blank character in this statement is a separate token,
> except for the if keyword and the two instances of the identifier big.
>
> In fact, C programs are broken into tokens twice....

— From C Traps and Pitfalls, Andrew Koenig.


My question is: Why is the if keyword and the two instances of the identifier big not separate tokens? What are they?

答案1

得分: 2

这段文字的意思是:“这个表达式中的每个字符都是一个标记,除了用于形成 ifbig 的字符。” 对于 ifif 是一个标记,但分别不包括字符 if

也就是说,这个表达式由以下标记组成:if(x<big)big=x;

英文:

The text means to say "every character in this expression is a token, except the characters used to form if and big". In case of if then if is a token, but not the characters i and f respectively.

That is, this expression consists of the tokens if, (, x, &lt;, big, ), big, =, x, ;.

huangapple
  • 本文由 发表于 2023年3月3日 20:29:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75627093.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定