Basic Pascal Tutorial/Chapter 1/Identifiers/zh CN: what changed
Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | 1B - 标识符 (原作者: Tao Yue, 状态: 已更改) | |
| 2 | 2 | ||
| 3 | 3 | 标识符是一些名字,用于引用存储的值,例如变量和常量。同样,每个程序都必须被一个标识符标识(明白?)。 | |
| 4 | 4 | ||
| 5 | 5 | 标识符命名的规则: | |
| 6 | 6 | ||
| 7 | 7 | - 必须以一个英文字母或者下划线(_)开始。 | |
| 8 | 8 | - 后面可以是英文字母,数字或者下划线(_). | |
| 9 | 9 | - 不能含有如下特殊字符: | |
| 10 | 10 | ||
| 11 | - | ||
| 11 | + | ```text | |
| 12 | 12 | ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \ | |
| 13 | 13 | ``` | |
| 14 | 14 | ||
| 15 | 15 | # 保留字 | |
| 16 | 16 | ||
| 17 | 17 | 有几个标识符是被Pascal已经占用的,你不能将他们用作你自定义的标识符。 根据[FPC参考](http://lazarus-ccr.sourceforge.net/fpcdoc/ref/ref.html),他们分为如下三类: | |
| 18 | 18 | ||
| 19 | 19 | - Turbo Pascal保留字 | |
| 20 | 20 | - Delphi 保留字 | |
| 21 | 21 | - FPC 保留字 | |
| 22 | 22 | ||
| 23 | 23 | ### Turbo Pascal保留字 | |
| 24 | 24 | ||
| 25 | 25 | | | | | | | | | | | |
| 26 | 26 | |----|----|----|----|----|----|----|----| | |
| 27 | 27 | | absolute | and | array | asm | begin | break | case | const | | |
| 28 | 28 | | constructor | continue | destructor | div | do | downto | else | end | | |
| 29 | 29 | | file | for | function | goto | if | implementation | in | inherited | | |
| 30 | 30 | | inline | interface | label | mod | nil | not | object | of | | |
| 31 | 31 | | on | operator | or | packed | procedure | program | record | reintroduce | | |
| 32 | 32 | | repeat | self | set | shl | shr | string | then | to | | |
| 33 | 33 | | type | unit | until | uses | var | while | with | xor | | |
| 34 | 34 | ||
| 35 | 35 | ### Delphi 保留字 | |
| 36 | 36 | ||
| 37 | 37 | Delphi(II)保留字跟Turbo Pascal一样,但是增加了如下内容: | |
| 38 | 38 | ||
| 39 | 39 | | | | | | | | | | |
| 40 | 40 | |-----|---------|--------|----------|--------------|-----------|----------------| | |
| 41 | 41 | | as | class | except | exports | finalization | finally | initialization | | |
| 42 | 42 | | is | library | on | property | raise | threadvar | try | | |
| 43 | 43 | ||
| 44 | 44 | ### Free Pascal 保留字 | |
| 45 | 45 | ||
| 46 | 46 | 除了拥有Turbo Pascal和Delphi的保留字之外,Free Pascal还增加了下面的保留字: | |
| 47 | 47 | ||
| 48 | 48 | | | | | | | | |
| 49 | 49 | |---------|------|-------|-----|------| | |
| 50 | 50 | | dispose | exit | false | new | true | | |
| 51 | 51 | ||
| 52 | 52 | 另外,Pascal有几个预先定义的标识符。你可以用你自己的定义来覆盖他们,但这样做你就没法使用这些标识符在Pascal中原来所具有的功能了。 | |
| 53 | 53 | ||
| 54 | 54 | | | | | | | | | | | |
| 55 | 55 | |-------|-------------|---------|---------|------|---------|--------|------| | |
| 56 | 56 | | abs | arctan | boolean | char | cos | dispose | eof | eoln | | |
| 57 | 57 | | exp | false | input | integer | ln | maxint | new | odd | | |
| 58 | 58 | | ord | output | pack | page | pred | read | readln | real | | |
| 59 | 59 | | reset | rewrite | round | sin | sqr | sqrt | succ | text | | |
| 60 | 60 | | true | trunc write | writeln | | | | | | | |
| 61 | 61 | ||
| 62 | 62 | Pascal是不区分大小写的!MyProgram,MYPROGRAM和mYpRoGrAm这三者是完全相同的。但为了可读性考虑,最好有意义地使用大小写! | |
| 63 | 63 | ||
| 64 | 64 | 标识符长度可以是任意的,但是许多Pascal编译器实际上只看开头的大约32个字符。也就是说,下面两个标识符: | |
| 65 | 65 | ||
| 66 | - | ||
| 66 | + | ```text | |
| 67 | 67 | ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFAlphaBeta | |
| 68 | 68 | ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGammaDelta | |
| 69 | 69 | ``` | |
| 70 | 70 | ||
| 71 | 71 | 可能对于某些编译器来说它们两者是相同的,因为第一个不同之处出现在第33个字符。 | |
| 72 | 72 | ||
| 73 | 73 | 为了让你的代码兼容所有的编译器,使用合理长度的标识符——最多15个字符。这样,你打字的时候也省事。 | |
| 74 | 74 | ||
| 75 | 75 | | | | | | |
| 76 | 76 | |----|----|----| | |
| 77 | 77 | | [[Basic Pascal Tutorial/Chapter 1/Program Structure/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 1/Constants/zh CN|下一页]] | | |
| 78 | 78 | ||
| 79 | 79 | --- | |
| 80 | 80 | *From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 1/Identifiers/zh CN", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 81 | 81 | Category: zh |
