Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 1/Identifiers/zh CN: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
111B - 标识符 (原作者: Tao Yue, 状态: 已更改)
22
33标识符是一些名字,用于引用存储的值,例如变量和常量。同样,每个程序都必须被一个标识符标识(明白?)。
44
55标识符命名的规则:
66
77- 必须以一个英文字母或者下划线(_)开始。
88- 后面可以是英文字母,数字或者下划线(_).
99- 不能含有如下特殊字符:
1010
11-``  ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \ ``
11+```
12+ ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \
13+```
1214
1315# 保留字
1416
1517有几个标识符是被Pascal已经占用的,你不能将他们用作你自定义的标识符。 根据[FPC参考](http://lazarus-ccr.sourceforge.net/fpcdoc/ref/ref.html),他们分为如下三类:
1618
1719- Turbo Pascal保留字
1820- Delphi 保留字
1921- FPC 保留字
2022
2123### Turbo Pascal保留字
2224
2325| | | | | | | | |
2426|----|----|----|----|----|----|----|----|
2527| absolute | and | array | asm | begin | break | case | const |
2628| constructor | continue | destructor | div | do | downto | else | end |
2729| file | for | function | goto | if | implementation | in | inherited |
2830| inline | interface | label | mod | nil | not | object | of |
2931| on | operator | or | packed | procedure | program | record | reintroduce |
3032| repeat | self | set | shl | shr | string | then | to |
3133| type | unit | until | uses | var | while | with | xor |
3234
3335### Delphi 保留字
3436
3537Delphi(II)保留字跟Turbo Pascal一样,但是增加了如下内容:
3638
3739| | | | | | | |
3840|-----|---------|--------|----------|--------------|-----------|----------------|
3941| as | class | except | exports | finalization | finally | initialization |
4042| is | library | on | property | raise | threadvar | try |
4143
4244### Free Pascal 保留字
4345
4446除了拥有Turbo Pascal和Delphi的保留字之外,Free Pascal还增加了下面的保留字:
4547
4648| | | | | |
4749|---------|------|-------|-----|------|
4850| dispose | exit | false | new | true |
4951
5052另外,Pascal有几个预先定义的标识符。你可以用你自己的定义来覆盖他们,但这样做你就没法使用这些标识符在Pascal中原来所具有的功能了。
5153
5254| | | | | | | | |
5355|-------|-------------|---------|---------|------|---------|--------|------|
5456| abs | arctan | boolean | char | cos | dispose | eof | eoln |
5557| exp | false | input | integer | ln | maxint | new | odd |
5658| ord | output | pack | page | pred | read | readln | real |
5759| reset | rewrite | round | sin | sqr | sqrt | succ | text |
5860| true | trunc write | writeln | | | | | |
5961
6062Pascal是不区分大小写的!MyProgram,MYPROGRAM和mYpRoGrAm这三者是完全相同的。但为了可读性考虑,最好有意义地使用大小写!
6163
6264标识符长度可以是任意的,但是许多Pascal编译器实际上只看开头的大约32个字符。也就是说,下面两个标识符:
6365
64-`    ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFAlphaBeta`\
65-`    ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGammaDelta`
66+```
67+ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFAlphaBeta
68+ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGammaDelta
69+```
6670
6771可能对于某些编译器来说它们两者是相同的,因为第一个不同之处出现在第33个字符。
6872
6973为了让你的代码兼容所有的编译器,使用合理长度的标识符——最多15个字符。这样,你打字的时候也省事。
7074
7175| | | |
7276|----|----|----|
7377| [[Basic Pascal Tutorial/Chapter 1/Program Structure/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 1/Constants/zh CN|下一页]] |
7478
7579---
7680*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).*
7781Category: zh

Back to history