16.5 Blocks

Units and programs are made of blocks. A block is made of declarations of labels, constants, types, variables and functions or procedures. Blocks can be nested in certain ways, i. e., a procedure or function declaration can have blocks in themselves. A block looks like the following:

_________________________________________________________________________________________________________
Blocks

--block -declaration-part- statement-part--------------------------------

--declaration-part---|-----------------------------------------------
                |------ label- declaration- part------||
                |---  constant- declaration-part ---||
                |---resourcestring-declaration- part---||
                |-----vatyrpiaeb- dlee-cdlaecrlaartiaonti-opna- prtart -----||
                |-----property-declaration- part-----||
                |---thread- variable- declaration-part--||
                ||procedure- function-declaration- part-||
                ||----operator- declaration- part----||
                |---------exports- clause-------- |
                --------------------------------

--label- declaration-part- label--|label---;------------------------------
                          --,----

--constant- declaration-part const---|---constant- declaration---------------
                             ||-typed- constant- declaration-||
                             -------------------------|

--                      -            ---                    ----
  resourcestring- declaration-part  resourcestring  -string- constant- declaration|

--                -    ---             -------------------------
  type-declaration- part type  -type- declaration-|

--variable- declaration-part- var--|variable- declaration---------------------
                           ------------------

--thread- variable-declaration- part -threadvar--|variable- declaration -----------
                                     ------------------

--property-declaration- part---property- definition --------------------------
                       ----------------|

--procedure- function- declaration- part---procedure- declaration--------------
                              | --function- declaration --| |
                              | -constructor-declaration-| |
                              | |destructor- declaration-| |
                              | -------------------- |
                              -----------------------

--statement- part-compound- statement----------------------------------
___________________________________________________________________

Labels that can be used to identify statements in a block are declared in the label declaration part of that block. Each label can only identify one statement.

Constants that are to be used only in one block should be declared in that block’s constant declaration part.

Variables that are to be used only in one block should be declared in that block’s variable declaration part.

Types that are to be used only in one block should be declared in that block’s type declaration part.

Lastly, functions and procedures that will be used in that block can be declared in the procedure/function declaration part.

These four declaration parts can be intermixed, there is no required order other than that you cannot use (or refer to) identifiers that have not yet been declared.

After the different declaration parts comes the statement part. This contains any actions that the block should execute. All identifiers declared before the statement part can be used in that statement part.