Difference between revisions of "Basic Pascal Tutorial/Chapter 1/Identifiers"
(New page: 1B - Identifiers (author: Tao Yue, state: unchanged) Identifiers are names that allow you to reference stored values, such as variables and constants. Also, every program must be identifi...) |
|||
Line 1: | Line 1: | ||
− | 1B - Identifiers (author: Tao Yue, state: | + | 1B - Identifiers (author: Tao Yue, state: changed) |
Identifiers are names that allow you to reference stored values, such as variables and constants. Also, every program must be identified (get it?) by an identifier. | Identifiers are names that allow you to reference stored values, such as variables and constants. Also, every program must be identified (get it?) by an identifier. | ||
Line 5: | Line 5: | ||
Rules for identifiers: | Rules for identifiers: | ||
− | * Must begin with a letter from the English alphabet. | + | * Must begin with a letter from the English alphabet or an underscore (_). |
* Can be followed by alphanumeric characters (alphabetic characters and numerals), or the underscore (_). | * Can be followed by alphanumeric characters (alphabetic characters and numerals), or the underscore (_). | ||
* May not contain special characters, such as: | * May not contain special characters, such as: | ||
− | ~ ! @ # $ % ^ & * ( ) | + | ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \ |
− | Several identifiers are reserved in Pascal -- you cannot use them as your own identifiers. | + | =Reserved words= |
+ | Several identifiers are reserved in Pascal -- you cannot use them as your own identifiers. | ||
+ | According to the FPC Reference they are grouped in: | ||
+ | * Turbo Pascal reserved words | ||
+ | * Delphi reserved words | ||
+ | * FPC reserved words | ||
+ | |||
+ | ==Turbo Pascal reserved words== | ||
{| style="font-weight:bold; background-color:#f5f5f5" cellspacing=5 | {| style="font-weight:bold; background-color:#f5f5f5" cellspacing=5 | ||
− | |and || array || begin || case | + | |absolute || and || array || asm || begin || break || case || const |
+ | |- | ||
+ | |constructor||continue || destructor || div || do || downto||else || end | ||
+ | |- | ||
+ | | file || for || function || goto || if||implementation ||in ||inherited | ||
|- | |- | ||
− | | | + | | inline || interface || label || mod || nil || not || object|| of |
|- | |- | ||
− | | | + | | or || packed ||procedure || program || record ||reintroduce || repeat || self |
|- | |- | ||
− | | | + | | set || shl || shr || string || then || to || type || unit |
|- | |- | ||
− | | | + | | uses || var || while || with || xor || || || |
|} | |} | ||
− | |||
Also, Pascal has several pre-defined identifiers. You can replace them with your own definitions, but then you'd be deleting part of the functionality of Pascal. | Also, Pascal has several pre-defined identifiers. You can replace them with your own definitions, but then you'd be deleting part of the functionality of Pascal. | ||
{| style="font-weight:bold; background-color:#f5f5f5" cellspacing=5 | {| style="font-weight:bold; background-color:#f5f5f5" cellspacing=5 |
Revision as of 17:34, 4 February 2008
1B - Identifiers (author: Tao Yue, state: changed)
Identifiers are names that allow you to reference stored values, such as variables and constants. Also, every program must be identified (get it?) by an identifier.
Rules for identifiers:
- Must begin with a letter from the English alphabet or an underscore (_).
- Can be followed by alphanumeric characters (alphabetic characters and numerals), or the underscore (_).
- May not contain special characters, such as:
~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \
Reserved words
Several identifiers are reserved in Pascal -- you cannot use them as your own identifiers. According to the FPC Reference they are grouped in:
- Turbo Pascal reserved words
- Delphi reserved words
- FPC reserved words
Turbo Pascal reserved words
absolute | and | array | asm | begin | break | case | const |
constructor | continue | destructor | div | do | downto | else | end |
file | for | function | goto | if | implementation | in | inherited |
inline | interface | label | mod | nil | not | object | of |
or | packed | procedure | program | record | reintroduce | repeat | self |
set | shl | shr | string | then | to | type | unit |
uses | var | while | with | xor |
Also, Pascal has several pre-defined identifiers. You can replace them with your own definitions, but then you'd be deleting part of the functionality of Pascal.
abs | arctan | boolean | char | cos | dispose | eof | eoln |
exp | false | input | integer | ln | maxint | new | odd |
ord | output | pack | page | pred | read | readln | real |
reset | rewrite | round | sin | sqr | sqrt | succ | text |
true | trunc write | writeln |
Pascal is not case sensitive! MyProgram, MYPROGRAM, and mYpRoGrAm are equivalent. But for readability purposes, it is a good idea to use meaningful capitalization!
Identifiers can be any length, but many Pascal compilers will only look at the first 32 characters or so. That is,
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFAlphaBeta ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGammaDelta
may be equivalent to some Pascal compilers because the differences begin in the 33rd character.
To make your code compilable by all compilers, use a reasonable length for identifiers -- up to 15 characters. That way, you'll also save on typing.
previous | contents | next |