Sign in Join
Wiki copytemporary

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.

OldNewLine
111B - 标识符 (原作者: Tao Yue, 状态: 已更改)
22
33标识符是一些名字,用于引用存储的值,例如变量和常量。同样,每个程序都必须被一个标识符标识(明白?)。
44
55标识符命名的规则:
66
77- 必须以一个英文字母或者下划线(_)开始。
88- 后面可以是英文字母,数字或者下划线(_).
99- 不能含有如下特殊字符:
1010
11-```
11+```text
1212 ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \
1313```
1414
1515# 保留字
1616
1717有几个标识符是被Pascal已经占用的,你不能将他们用作你自定义的标识符。 根据[FPC参考](http://lazarus-ccr.sourceforge.net/fpcdoc/ref/ref.html),他们分为如下三类:
1818
1919- Turbo Pascal保留字
2020- Delphi 保留字
2121- FPC 保留字
2222
2323### Turbo Pascal保留字
2424
2525| | | | | | | | |
2626|----|----|----|----|----|----|----|----|
2727| absolute | and | array | asm | begin | break | case | const |
2828| constructor | continue | destructor | div | do | downto | else | end |
2929| file | for | function | goto | if | implementation | in | inherited |
3030| inline | interface | label | mod | nil | not | object | of |
3131| on | operator | or | packed | procedure | program | record | reintroduce |
3232| repeat | self | set | shl | shr | string | then | to |
3333| type | unit | until | uses | var | while | with | xor |
3434
3535### Delphi 保留字
3636
3737Delphi(II)保留字跟Turbo Pascal一样,但是增加了如下内容:
3838
3939| | | | | | | |
4040|-----|---------|--------|----------|--------------|-----------|----------------|
4141| as | class | except | exports | finalization | finally | initialization |
4242| is | library | on | property | raise | threadvar | try |
4343
4444### Free Pascal 保留字
4545
4646除了拥有Turbo Pascal和Delphi的保留字之外,Free Pascal还增加了下面的保留字:
4747
4848| | | | | |
4949|---------|------|-------|-----|------|
5050| dispose | exit | false | new | true |
5151
5252另外,Pascal有几个预先定义的标识符。你可以用你自己的定义来覆盖他们,但这样做你就没法使用这些标识符在Pascal中原来所具有的功能了。
5353
5454| | | | | | | | |
5555|-------|-------------|---------|---------|------|---------|--------|------|
5656| abs | arctan | boolean | char | cos | dispose | eof | eoln |
5757| exp | false | input | integer | ln | maxint | new | odd |
5858| ord | output | pack | page | pred | read | readln | real |
5959| reset | rewrite | round | sin | sqr | sqrt | succ | text |
6060| true | trunc write | writeln | | | | | |
6161
6262Pascal是不区分大小写的!MyProgram,MYPROGRAM和mYpRoGrAm这三者是完全相同的。但为了可读性考虑,最好有意义地使用大小写!
6363
6464标识符长度可以是任意的,但是许多Pascal编译器实际上只看开头的大约32个字符。也就是说,下面两个标识符:
6565
66-```
66+```text
6767 ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFAlphaBeta
6868 ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGammaDelta
6969```
7070
7171可能对于某些编译器来说它们两者是相同的,因为第一个不同之处出现在第33个字符。
7272
7373为了让你的代码兼容所有的编译器,使用合理长度的标识符——最多15个字符。这样,你打字的时候也省事。
7474
7575| | | |
7676|----|----|----|
7777| [[Basic Pascal Tutorial/Chapter 1/Program Structure/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 1/Constants/zh CN|下一页]] |
7878
7979---
8080*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).*
8181Category: zh

Back to history