Difference between revisions of "Reserved words"

From Lazarus wiki
Jump to navigationJump to search
("continue" is not restricted to for-loops; it can be used in while- and repeat-loops as well)
 
(39 intermediate revisions by 6 users not shown)
Line 4: Line 4:
  
 
The keywords of the individual <!---[[Compiler Mode|compiler modes]]--->[[:Category:Modes|compiler modes]] are summarized as follows:
 
The keywords of the individual <!---[[Compiler Mode|compiler modes]]--->[[:Category:Modes|compiler modes]] are summarized as follows:
 +
 
* [[Mode TP|Turbo Pascal mode]]: the [[Turbo Pascal]] keywords are available for you to use
 
* [[Mode TP|Turbo Pascal mode]]: the [[Turbo Pascal]] keywords are available for you to use
 
* [[Mode Delphi | Delphi mode]]: the Turbo Pascal and Object Pascal keywords are available for you to use
 
* [[Mode Delphi | Delphi mode]]: the Turbo Pascal and Object Pascal keywords are available for you to use
 
* [[Mode ObjFPC | Extended Free Pascal mode]]: the Turbo Pascal and Object Pascal keywords are available for you to use
 
* [[Mode ObjFPC | Extended Free Pascal mode]]: the Turbo Pascal and Object Pascal keywords are available for you to use
  
Note: the terms keywords and reserved words are used interchangeably here ''is this correct?''
+
Keywords are '''reserved''' words, ie they cannot be defined as [[Identifier|identifiers]] by the programmer. This means that you cannot use these words to name your variables, constants, function and procedure names, class names, etc. In Pascal, in the source code, keywords are often shown in bold.
  
''To do'': insert explanation/link to the online Free Pascal manual of what a keyword/reserved word is: e.g. can you name your variables "if" etc.
+
==Reserved words in Turbo Pascal==
  
''To do'': create pages for the keywords if they don't exist yet (e.g. translate from the German version) and link to the online Free Pascal manual section on that keyword in those pages.
+
The following keywords occur in Turbo Pascal mode:
  
==Reserved words in Turbo Pascal==
 
The following keywords occur in Turbo Pascal mode:
 
 
{| class = "wikitable"
 
{| class = "wikitable"
 
|-
 
|-
! keyword !! description
+
! Keyword !! Description
 
|-
 
|-
 
| [[And|and]] || Boolean operator requiring both conditions are true for the result to be true
 
| [[And|and]] || Boolean operator requiring both conditions are true for the result to be true
Line 28: Line 27:
 
| [[Begin|begin]] || start of a [[Block|block]] of code
 
| [[Begin|begin]] || start of a [[Block|block]] of code
 
|-
 
|-
| [[Break|break]] || exit a  [[Case|case]] statemenr
+
| [[Break|break]] || exit a  loop
 
|-
 
|-
 
| [[Case|case]] || select a particular segement of code to execute based on a value
 
| [[Case|case]] || select a particular segement of code to execute based on a value
Line 36: Line 35:
 
| [[Constructor|constructor]] || routine used to create an object
 
| [[Constructor|constructor]] || routine used to create an object
 
|-
 
|-
| [[Continue|continue]] || skips an iteration in a for-loop and restart execution at the beginning of the loop
+
| [[Continue|continue]] || skips an iteration in a loop and restart execution at the beginning of the loop
 
|-
 
|-
 
| [[Destructor|destructor]] || routine used to deallocate an object
 
| [[Destructor|destructor]] || routine used to deallocate an object
Line 48: Line 47:
 
| [[Else|else]] || used in [[If|if]] statement to provide an execution path when the if test fails
 
| [[Else|else]] || used in [[If|if]] statement to provide an execution path when the if test fails
 
|-
 
|-
| [[End|end]] || end of a block of code, a record or certain other constructs]
+
| [[End|end]] || end of a block of code, a record or certain other constructs
 
|-
 
|-
| [[False|false]] || boolean value indicating a test failed; opposite of [[True|true]]. As of FPC 3.0.0. False is no longer a keyword.
+
| [[False|false]] || boolean value indicating a test failed; opposite of [[True|true]]. '''As of FPC 3.0.0. False is no longer a keyword'''.
 
|-
 
|-
 
| [[File|file]] || external data structure, typically stored on disc
 
| [[File|file]] || external data structure, typically stored on disc
Line 66: Line 65:
 
| [[In|in]] || identifies elements in a collection
 
| [[In|in]] || identifies elements in a collection
 
|-
 
|-
| [[inline|inline]] || machine code inserted directly into a routine
+
| [[Inline|inline]] || machine code inserted directly into a routine
 
|-
 
|-
 
| [[Interface|interface]] || public declarations of routines in a [[Unit|unit]]
 
| [[Interface|interface]] || public declarations of routines in a [[Unit|unit]]
Line 82: Line 81:
 
| [[Of|of]] || defines the characteristics of a variable
 
| [[Of|of]] || defines the characteristics of a variable
 
|-
 
|-
| [[On|on]] ||
+
| [[On|on]] || defines an exception handling statement in the [[Except]] part of a [[Try]] statement
 
|-
 
|-
 
| [[Operator|operator]] || defines a routine used to implement an operator
 
| [[Operator|operator]] || defines a routine used to implement an operator
Line 110: Line 109:
 
| [[To|to]] || indicates a [[For|for]] variable is to be incremented
 
| [[To|to]] || indicates a [[For|for]] variable is to be incremented
 
|-
 
|-
| [[True|true]] || boolean value indicating a test succeeded; opposite of [[false]]. As of FPC 3.0.0. True is no longer a keyword.
+
| [[True|true]] || boolean value indicating a test succeeded; opposite of [[False]]. '''As of FPC 3.0.0. True is no longer a keyword'''.
 
|-
 
|-
 
| [[Type|type]] || declares kinds of records or new classes of variables
 
| [[Type|type]] || declares kinds of records or new classes of variables
Line 126: Line 125:
 
| [[With|with]] || reference the internal variables within a record without having to refer to the record itself
 
| [[With|with]] || reference the internal variables within a record without having to refer to the record itself
 
|-
 
|-
| [[Xor|xor]] || boolean operator used to invert an [[Or|or]] test
+
| [[Xor|xor]] || boolean operator used to invert and [[Or|or]] test
 
|}
 
|}
  
 
==Reserved words in Object Pascal==
 
==Reserved words in Object Pascal==
Object Pascal extends the (Turbo) Pascal language with both support for dealing more easily with objects (object orientation) as well as other newer/more advanced concepts (threads, etc).<br>
+
 
In addition to the reserved words in Turbo Pascal, the following reserved words are available in Delphi mode as well:<br>
+
Object Pascal extends the (Turbo) Pascal language with both support for dealing more easily with objects (object orientation) as well as other newer/more advanced concepts (threads, etc).
 +
 
 +
In addition to the reserved words in Turbo Pascal, the following reserved words are available in Delphi mode as well:
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 +
|-
 +
! Keyword !! Description
 
|-
 
|-
 
| [[As|as]] ||
 
| [[As|as]] ||
 
|-
 
|-
 
| [[Class|class]] ||
 
| [[Class|class]] ||
 +
|-
 +
| [[Constref|constref]] ||
 
|-
 
|-
 
| [[Dispose|dispose]] ||
 
| [[Dispose|dispose]] ||
Line 144: Line 150:
 
| [[Exit|exit]] ||
 
| [[Exit|exit]] ||
 
|-
 
|-
| [[Exports|exports]] ||
+
| [[Exports|exports]] || exports symbols which will be publicly available
 
|-
 
|-
 
| [[Finalization|finalization]] || introduces an optional 'finalization' part of a unit.
 
| [[Finalization|finalization]] || introduces an optional 'finalization' part of a unit.
Line 150: Line 156:
 
| [[Finally|finally]] || part of a try - finally - end block
 
| [[Finally|finally]] || part of a try - finally - end block
 
|-
 
|-
| [[Inherited|inherited]] || calls functionb/procedure from ancestor  class
+
| [[Inherited|inherited]] || calls function/procedure from ancestor  class
 
|-
 
|-
 
| [[Initialization|initialization]] || introduces an optional 'initialization' part of a unit.
 
| [[Initialization|initialization]] || introduces an optional 'initialization' part of a unit.
 
|-
 
|-
| [[Is|is]] ||
+
| [[Is|is]] || can be used as an [[Operator|operator]] or a [[modifier]]
 
|-
 
|-
| [[Library|library]] ||
+
| [[Library|library]] || used in a shared library unit instead of the reserved word [[Unit|unit]]
 
|-
 
|-
 
| [[New|new]] ||
 
| [[New|new]] ||
Line 166: Line 172:
 
| [[Property|property]] ||
 
| [[Property|property]] ||
 
|-
 
|-
| [[Raise|raise]] ||
+
| [[Raise|raise]] || causes an exception
 
|-
 
|-
| [[Self|self]] ||
+
| [[Self|self]] || reference to an instance of a class
 
|-
 
|-
| [[Threadvar|threadvar]] ||
+
| [[Threadvar|threadvar]] || declare global variable to be thread local
 
|-
 
|-
| [[Try|try]] ||
+
| [[Try|try]] || part of Try .. Finally or Try .. Exception block
 
|}
 
|}
  
 
==Reserved words in Extended Free Pascal==
 
==Reserved words in Extended Free Pascal==
 +
 
The reserved words in [[Mode ObjFPC|Extended Free Pascal mode]] include:
 
The reserved words in [[Mode ObjFPC|Extended Free Pascal mode]] include:
 +
 
* [[Mode TP|Turbo Pascal mode]] reserved words  
 
* [[Mode TP|Turbo Pascal mode]] reserved words  
 
* [[Mode Delphi|Object Pascal mode]] reserved words<br>
 
* [[Mode Delphi|Object Pascal mode]] reserved words<br>
  
 
==Modifiers (directives)==
 
==Modifiers (directives)==
The list below is a list of modifiers<br>
+
 
Modifiers are not strictly reserved words; however they are used in the same way as reserved words.<br>
+
Modifiers are not strictly reserved words; however they are used in the same way as reserved words.
See the Free Pascal manual for details.<br>
+
 
 +
See the [https://www.freepascal.org/docs-html/current/ref/ref.html Free Pascal Reference Guide] for details.
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 +
|-
 +
! Modifiers !! Description
 
|-
 
|-
 
| [[Absolute|absolute]] ||
 
| [[Absolute|absolute]] ||
 
|-
 
|-
| [[abstract]] || an abcstract class cannot be instantiated, only inherited
+
| [[abstract]] || an abstract class cannot be instantiated, only inherited
 
|-
 
|-
 
| [[alias]] ||
 
| [[alias]] ||
 
|-
 
|-
| [[assembler]] || assembler...end creates an assemby language block
+
| [[assembler]] || pure assembler routine: routine is defined by [[Asm|<syntaxhighlight lang="delphi" inline>asm</syntaxhighlight>]] … [[End|<syntaxhighlight lang="delphi" inline>end</syntaxhighlight>]]
 
|-
 
|-
| [[cdecl]] || C declaration mofifier
+
| [[cdecl]] || C declaration modifier
 
|-
 
|-
| [[cppdecl]] || C++ declaration mofifier
+
| [[Cppdecl]] || C++ declaration modifier
 
|-
 
|-
| [[default]] ||  
+
| [[default]] || For indexed properties to use them without specifying the property name
 
|-
 
|-
 
| [[export]] ||  
 
| [[export]] ||  
Line 204: Line 216:
 
| [[external]] ||  
 
| [[external]] ||  
 
|-
 
|-
| [[forward]] ||  
+
| [[Forward|forward]] || Allow a subroutine to be used before it is declared
 
|-
 
|-
| [[generic]] || class creation modfifier
+
| [[generic]] || class creation modifier
 
|-
 
|-
 
| [[index]] ||
 
| [[index]] ||
 
|-
 
|-
| [[local]] ||
+
| [[Local|local]] || A function/procedure modifier only usable with Linux (for Kylix compatibility)
 
|-
 
|-
 
| [[name]] ||
 
| [[name]] ||
 
|-
 
|-
| [[nostackframe]] ||
+
| [[nostackframe]] || compiler hint: omit stack frame if possible
 
|-
 
|-
| [[oldfpccall]] ||
+
| [[oldfpccall]] || ''deprecated'' subroutine calling convention
 
|-
 
|-
| [[override]] || overrriding of virtual functions
+
| [[Override|override]] || overriding of virtual functions
 
|-
 
|-
| [[pascal]] ||  
+
| [[pascal]] || use classic pascal calling convention
 
|-
 
|-
| [[private]] || private accessibility modifier, only class members can access data/functions/procedures
+
| [[Private|private]] || private accessibility modifier, only class members can access data/functions/procedures
 
|-
 
|-
| [[protected]] || protected accessibility modifier, accessibility modifier, class members and inherited classes can access data/functions/procedures
+
| [[Protected|protected]] || protected accessibility modifier, accessibility modifier, class members and inherited classes can access data/functions/procedures
 
|-
 
|-
| [[public]] || public accessibility modifier, public access to data/functions/procedures
+
| [[Public|public]] || public accessibility modifier, public access to data/functions/procedures
 
|-
 
|-
| [[published]] || accessibility modifier, published properties are visible in IDE ar can be written to .lfm
+
| [[Published|published]] || accessibility modifier, published properties are visible in IDE ar can be written to .lfm
 
|-
 
|-
| [[read]] || property read access  
+
| [[Read|read]] || property read access  
 
|-
 
|-
| [[Register|register]] ||
+
| [[Register|register]] || define routine’s calling convention: pass first n parameters via <abbr title="general purpose register">GPR</abbr>s
 
|-
 
|-
 
| [[Reintroduce|reintroduce]] ||
 
| [[Reintroduce|reintroduce]] ||
 
|-
 
|-
| [[safecall]] ||
+
| [[Safecall|safecall]] || subroutine calling convention
 
|-
 
|-
 
| [[softfloat]] ||
 
| [[softfloat]] ||
Line 242: Line 254:
 
| [[specialize]] || specialization of [[Generics|generic classes]]
 
| [[specialize]] || specialization of [[Generics|generic classes]]
 
|-
 
|-
| [[stdcall]] ||
+
| [[Stdcall|stdcall]] || subroutine calling convention
 
|-
 
|-
| [[virtual]] ||
+
| [[Virtual|virtual]] || describes a virtual method in OO programming
 
|-
 
|-
| [[write]] || property read access  
+
| [[Write|write]] || property write access  
 
|-
 
|-
 
|}
 
|}
  
 
==Unsupported Turbo Pascal modifiers==
 
==Unsupported Turbo Pascal modifiers==
 +
 +
{{Note|These modifiers '''are supported''' in the [[DOS]] cross compiler present in the FPC development version}}
 +
 
The reason why these modifiers are not supported is that these modifiers deal with 16 bit code for DOS. In other words, these modifiers have special meaning for 16 bit programming under DOS and Windows 3.x.
 
The reason why these modifiers are not supported is that these modifiers deal with 16 bit code for DOS. In other words, these modifiers have special meaning for 16 bit programming under DOS and Windows 3.x.
  
 
As Free Pascal does not support 16 bit code (only 32 and 64 bit), these modifiers are irrelevant in Free Pascal code.
 
As Free Pascal does not support 16 bit code (only 32 and 64 bit), these modifiers are irrelevant in Free Pascal code.
{{Note|However, these modifiers are supported in the [[DOS]] crosscompiler present in the FPC development version}}
 
  
[[Far|far]]<br>
+
{| class="wikitable"
[[Near|near]]<br>
+
|-
 +
| [[Far|far]] || access addresses outside of the current 64KB segment
 +
|-
 +
| [[Near|near]] || access addresses in the current 64KB segment
 +
|}
  
 
==More functionality==
 
==More functionality==
 +
 
Apart from the language features provided by the reserved words/keywords mentioned above, there is a lot of functionality available for the programmer in the various libraries:
 
Apart from the language features provided by the reserved words/keywords mentioned above, there is a lot of functionality available for the programmer in the various libraries:
  
Line 269: Line 288:
  
 
Apart from the libraries provided by FPC and Lazarus, there are more libraries/components available:
 
Apart from the libraries provided by FPC and Lazarus, there are more libraries/components available:
 +
 
* FPC user-supplied units: see the FPC wiki
 
* FPC user-supplied units: see the FPC wiki
 
* Lazarus CCR: components
 
* Lazarus CCR: components
 
* User-supplied code on the internet: see open source repositories like SourceForge and GitHub.
 
* User-supplied code on the internet: see open source repositories like SourceForge and GitHub.
  
[[category:Pascal]]{{AutoCategory}}
+
== See also ==
 +
 
 +
* [[Pascal basics]]

Latest revision as of 18:52, 12 January 2022

Deutsch (de) English (en) français (fr) polski (pl) русский (ru) 中文(中国大陆)‎ (zh_CN)

The keywords of the individual compiler modes are summarized as follows:

Keywords are reserved words, ie they cannot be defined as identifiers by the programmer. This means that you cannot use these words to name your variables, constants, function and procedure names, class names, etc. In Pascal, in the source code, keywords are often shown in bold.

Reserved words in Turbo Pascal

The following keywords occur in Turbo Pascal mode:

Keyword Description
and Boolean operator requiring both conditions are true for the result to be true
array multiple elements with the same name
asm start of code written in assembly language
begin start of a block of code
break exit a loop
case select a particular segement of code to execute based on a value
const declare an identifier with a fixed value, or a variable with an initialized value
constructor routine used to create an object
continue skips an iteration in a loop and restart execution at the beginning of the loop
destructor routine used to deallocate an object
div integer divide operator
do used to indicate start of a loop
downto used in a for loop to indicate the index variable is decremented
else used in if statement to provide an execution path when the if test fails
end end of a block of code, a record or certain other constructs
false boolean value indicating a test failed; opposite of true. As of FPC 3.0.0. False is no longer a keyword.
file external data structure, typically stored on disc
for loop used to increment or decrement a control variable
function define start of a routine that returns a result value
goto used to exit a segment of code and jump to another point
if test a condition and perform a set of instructions based on the result
implementation define the internal routines in unit
in identifies elements in a collection
inline machine code inserted directly into a routine
interface public declarations of routines in a unit
label defines the target jump point for a goto
mod operator used to return the remainder of an integer division
nil pointer value indicating the pointer does not contain a value
not boolean operator that negates the result of a test
object defines an object construct
of defines the characteristics of a variable
on defines an exception handling statement in the Except part of a Try statement
operator defines a routine used to implement an operator
or boolean operator which allows either of two choices to be used
packed indicates the elements of an array are to use less space (this keyword is primarily for compatibility with older programs as packing of array elements is generally automatic)
procedure define start of a routine that does not return a result value
program defines start of an application. This keyword is usually optional.
record group a series of variables under a single name
repeat loop through a section of code through an until statement as long as the result of the test is true
set group a collection
shl operator to shift a value to the left; equivalent to multiplying by a power of 2
shr operator to shift a value to the right; equivalent to dividing by a power of 2
string declares a variable that contains multiple characters
then indicates start of code in an if test
to indicates a for variable is to be incremented
true boolean value indicating a test succeeded; opposite of False. As of FPC 3.0.0. True is no longer a keyword.
type declares kinds of records or new classes of variables
unit separately compiled module
until indicates end test of a repeat statement
uses names units this program or unit refers to
var declare variables
while test a value and if true, loop through a section of code
with reference the internal variables within a record without having to refer to the record itself
xor boolean operator used to invert and or test

Reserved words in Object Pascal

Object Pascal extends the (Turbo) Pascal language with both support for dealing more easily with objects (object orientation) as well as other newer/more advanced concepts (threads, etc).

In addition to the reserved words in Turbo Pascal, the following reserved words are available in Delphi mode as well:

Keyword Description
as
class
constref
dispose
except
exit
exports exports symbols which will be publicly available
finalization introduces an optional 'finalization' part of a unit.
finally part of a try - finally - end block
inherited calls function/procedure from ancestor class
initialization introduces an optional 'initialization' part of a unit.
is can be used as an operator or a modifier
library used in a shared library unit instead of the reserved word unit
new
on
out
property
raise causes an exception
self reference to an instance of a class
threadvar declare global variable to be thread local
try part of Try .. Finally or Try .. Exception block

Reserved words in Extended Free Pascal

The reserved words in Extended Free Pascal mode include:

Modifiers (directives)

Modifiers are not strictly reserved words; however they are used in the same way as reserved words.

See the Free Pascal Reference Guide for details.

Modifiers Description
absolute
abstract an abstract class cannot be instantiated, only inherited
alias
assembler pure assembler routine: routine is defined by asm … end
cdecl C declaration modifier
Cppdecl C++ declaration modifier
default For indexed properties to use them without specifying the property name
export
external
forward Allow a subroutine to be used before it is declared
generic class creation modifier
index
local A function/procedure modifier only usable with Linux (for Kylix compatibility)
name
nostackframe compiler hint: omit stack frame if possible
oldfpccall deprecated subroutine calling convention
override overriding of virtual functions
pascal use classic pascal calling convention
private private accessibility modifier, only class members can access data/functions/procedures
protected protected accessibility modifier, accessibility modifier, class members and inherited classes can access data/functions/procedures
public public accessibility modifier, public access to data/functions/procedures
published accessibility modifier, published properties are visible in IDE ar can be written to .lfm
read property read access
register define routine’s calling convention: pass first n parameters via GPRs
reintroduce
safecall subroutine calling convention
softfloat
specialize specialization of generic classes
stdcall subroutine calling convention
virtual describes a virtual method in OO programming
write property write access

Unsupported Turbo Pascal modifiers

Light bulb  Note: These modifiers are supported in the DOS cross compiler present in the FPC development version

The reason why these modifiers are not supported is that these modifiers deal with 16 bit code for DOS. In other words, these modifiers have special meaning for 16 bit programming under DOS and Windows 3.x.

As Free Pascal does not support 16 bit code (only 32 and 64 bit), these modifiers are irrelevant in Free Pascal code.

far access addresses outside of the current 64KB segment
near access addresses in the current 64KB segment

More functionality

Apart from the language features provided by the reserved words/keywords mentioned above, there is a lot of functionality available for the programmer in the various libraries:

  • RTL: Run-Time Library, available for all FPC and Lazarus programs
  • FCL: Free Component Library: a core set of libraries available for Lazarus programs and usually for FPC (FPC can be compiled without it, but that only happens on purpose for low-memory embedded systems etc)
  • FPC Packages: other packages provided by FPC
  • Lazarus components: these are Lazarus components that can be dropped on a form and often based on FCL or FPC packages
  • Lazarus utility functions: e.g. the fileutil unit.

Apart from the libraries provided by FPC and Lazarus, there are more libraries/components available:

  • FPC user-supplied units: see the FPC wiki
  • Lazarus CCR: components
  • User-supplied code on the internet: see open source repositories like SourceForge and GitHub.

See also