Basic Pascal Tutorial/Chapter 1/Identifiers/bg

From Lazarus wiki
Revision as of 16:47, 20 April 2021 by Alpinistbg (talk | contribs) (Created page with "{{Identifiers}} {{TYNavigator|Program_Structure/bg|Constants/bg}} <font size='5'>Идентификатори</font> 1B - Identifiers (author: Tao Yue, state: changed) Ид...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

български (bg) Deutsch (de) English (en) français (fr) italiano (it) 日本語 (ja) 한국어 (ko) русский (ru) 中文(中国大陆)‎ (zh_CN)

 ◄   ▲   ► 

Идентификатори

1B - Identifiers (author: Tao Yue, state: changed)

Идентификаторите са имена, които ви позволяват да се позовавате на съхранени стойности, като променливи и константи. Също така, всяка програма трябва да бъде идентифицирана (схванахте ли?) с идентификатор.

Правила за идентификаторите:

  • Трябва да започва с латинска буква (a..z или A..Z, Pascal не различава големи от малки букви) от или долна черта (_).
  • Може да бъде последвано от още букви (a..z, A..Z), цифри (0..9) или долни черти (_), във всякаква комбинация.
  • Не може да бъде резервирана дума като например begin, for, case, absolute и др.
  • Не може да съдържа специални символи, като:
  ~! @ # $% ^ & * () + `- = {} []:"; '<>?,. / | \ (или интервал) 

Запазени думи

В Pascal някои идентификатори са запазени и не можете да ги използвате като свои собствени такива. Според FPC справочник те са групирани така:

  • Запазени думи от Turbo Pascal
  • Запазени думи от Delphi
  • Запазени думи от Free Pascal

Запазени думи от Turbo Pascal

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
on operator or packed procedure program record reintroduce
repeat self set shl shr string then to
type unit until uses var while with xor

Запазени думи от Delphi

Запазените думи от Delphi (II) са същите като тези от Turbo Pascal, плюс следните:

as class except exports finalization finally initialization
is library on property raise threadvar try

Запазени думи от Free Pascal

В допълнение към запазените думи от Turbo Pascal и Delphi, Free Pascal запазва още и следните:

dispose exit false new true break continue

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!

There are two possible methods you could choose to apply to your identifiers: CamelCase and underscore as space. CamelCase, as it appears, means that separate words in an identifier are capitalized, so that you have newPerson or NewPerson instead of newperson. Using underscore as space means you separate words in an identifier with underscores, so that you have new_person instead of newperson. Or you could combine the two, so that you have new_Person or New_Person instead of newperson.

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. Free Pascal limits identifiers to 127 characters.

This is extremely generous. The original Pascal compiler for the CDC 6000 mainframe only noticed the first 10 characters of an identifier. This was because the CDC had a 60 bit word, and by using 6 bit characters (all upper case letters plus digits and some punctuation) an identifier could fit in one word. You could have more than 10 characters in an identifier, but only the first 10 counted, so ThisIsObviouslyAVeryLongNamw and ThisIsObviouslyAnEvenLongerName would be considered the same.

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.

While it is a good idea to make identifiers to be mnemonic with the use of longer names, there is nothing wrong with using very short identifiers in specific uses. it is extremely common to use I, J, and K< as the control variable in a for loop.


 ◄   ▲   ►