,ll 6.6
,cs 10
,pl 66
,lm 0.2,0.5
,pn 7
,ju
,hd
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)
,,
,ft

,ce 1
5-##
,,
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)

,ce
STATEMENTS

Statements are the part of the Pascal program that actually do the work required. Statements may only appear within the begin..end of the program block or of a procedure or function block. Remember that semicolons are used as statement separators in Pascal, not terminators.

statement = [ unsigned-integer : ] (null-statement |
            compound-statement | assignment-statement | 
            case-statement | if-then-else-statement |
            for-statement | repeat-statement | while-statement |
            exit-statement | goto-statement | with-statement |
            procedure-call | inline-statement)

 
    statement :

 
       unsigned integer        :

 
             begin        statement        end

                                                      {compound}
                             ;
,ce 24
                                                      {null}


case statement

exit statement

if statement

with statement

repeat statement

while statement

goto statement

for statement

procedure call

assignment statement

inline statement


The null-statement consists of nothing and useful in case statements to do nothing if a certain case is met, it is also found when extra semicolons are used, as in :

   begin
     writeln ('help') ;
   end

A null statement is found between the semicolon and the end, and will do no harm.
,ce
STATEMENTS

,ce
COMPOUND STATEMENT

The compound statement allows grouping of Pascal statements to act as one statement. The sequence :

  begin
    k := 5 ;
    j := -k
  end

Can now represent one statement. A compound statement may contain any other kind of Pascal statement within it. The begin .. end section of a block is essentially a compound statement that must be present.

compound-statement = begin statement {; statement} end

,ce
ASSIGNMENT STATEMENT

The assignment statements allows the result of an expression (covered earlier in this chapter) to be placed into a variable or function return variable.

assignment-statement = (variable | function-return) := expression


       variable

                            :=        expression

    function-return
      identifier

The following table lists the expression types that are compatible (can be assigned) to the various variable types :

variable type         acceptable expression                      

boolean               boolean
character             character
enumerated            enumerated (any)
integer               integer
hex                   hex
subrange              subrange (same base type), base type
longinteger           longinteger or integer
longhex               longhex or hex
real                  real, longinteger, or integer
string                string, character, array* 
array                 array (same size), character*, string*
record                record (same size)
set                   set (any)
pointer               pointer or hex

NOTE : The acceptable expressions marked with an asterisk "*" may only be used if the array is less than 127 bytes.
,pg
,ce
STATEMENTS

,ce
CONDITIONAL STATEMENTS

Conditional statements select a statement to execute based on the value of an expression.

CASE STATEMENT

The case statement selects zero or one statement to execute based on the value of a selector expression. The expression is compared against constants until a match is found, at which point the statement that goes with the matching constant is executed. The expression may be boolean, character, enumerated, integer, hex, or string. Constants of the same type as the expression are used to determine which statement to execute. More than one constant may be specified to select a statement and except for string selectors, a subrange of constants may be used to compare against. Automatic conversion of some types of constants is available as noted in chapter 4.

If none of the constants match, then none of the statements will be executed. If it is desired that a statement be executed when there is no match then an optional "else" or "otherwise" clause may be inserted at the end of the case statement. There is no check for duplication of case constants in this compiler, the comparisons are done in the order of declaration. 

For example, the following code will pick out carriage returns and line feeds separately from all other control characters :

     case ch of
       $D : {process carriage return} ;
       $A : {process line feed} ;
       $0..$1F : {process all other control characters}
       else {process non-control characters}
     end ;

Note that boolean and character selectors are the fastest, followed by integer and hex, with string being the slowest.

case-statement = case expression of case-selection [;] [(else |
                 otherwise) statement [;]] end
case-selection = case-constant-list : statement
                 {; case-constant-list : statement}
case-constant-list = constant [.. constant]
                     {, constant [.. constant]}

   case        expression      of


       constant      ..     constant       :     statement

                  
                     ,
                                   ;

                                          otherwise 

    end      ;      statement               else           ;

,pg
,ce
CONDITIONAL STATEMENTS

IF-THEN-ELSE STATEMENT

The if-then-else statement allows execution of the statement following the "then" if the boolean expression following the "if" is true. It will execute the statement following the "else" if the boolean expression is false. The else clause may be left off, leaving you with an if-then statement which will only execute the statement if the boolean expression is true. Note that in nested if-then-else statements an else always goes with the closest unpaired then, such that in :

if expr1 then if expr2 then stat1 else stat2 ; 

is equivalent to and should be formatted as :

if expr1
  then
    if expr2
      then
        stat1
      else
        stat2 {goes with second if} ;

if-statement = if boolean-expression then statement
                                    [else statement]

   if   expression    then   statement      else    statement


,ce
REPETITIVE STATEMENTS

The repetitive statements are used for forming loops to execute statements multiple times until a condition is met. The repetitive statements may be nested to at most 20 levels (all repetitive statements combined, not each type separately).

FOR STATEMENT

There are two forms of the for statement, the first in which one is added to the control variable each time through the loop. This form is specified by following the first expression with the word "to". The value of the first expressions is assigned to the control variable. This value is then compared against the second expression, and if it is less than or equal will execute the statement. After the execution of the statement the control variable is compared against the second expression and if equal, the for statement is terminated. If the control variable is not equal then one is added to it and the statement is executed again. This process repeats until the control variable is equal to the second expression.

The second form is where one is subtracted from the control variable. This form is specified by following the first expression with the word "downto". The value of the first expression is assigned to the control variable. This value is then compared against the second expression, and if it is greater than or equal will execute the statement. After the execution of the statement the control variable is compared against the second expression and if equal, the for statement is terminated. If the control variable is not equal then one is subtracted from it and the statement is executed again. 
,ce
REPETITIVE STATEMENTS

This process repeats until the control variable is equal to the second expression.

In either case if the statement is never executed then the control variable will have the value of the first expression. If the for statement finishes normally then the control variable will have the value of the second expression.

The control variable and expression type may be boolean, character, integer, hex, or enumerated. Automatic type conversions of certain constants (for the limits) is available as noted in chapter 4.

Example :   for i := 1 to n - 1 do
              a[i] := i ;
     
for-statement = for variable := expression (to | downto)
                                expression do statement

    for        variable        :=     expression

 
           to
                      expression      do      statement
           downto


REPEAT STATEMENT

This statement will execute one or more statements until a condition is met. The statement(s) will be executed until the boolean expression is true. An endless loop can be created by making the expression equal to the boolean constant "false", in this case an unconditional branch will be used in the code generated.

Note that the statement(s) will always be executed at least once since the test is done at the end of the loop.

Example :   repeat
              write ('Wie hei~en Sie ? ') ;
              read (name)
            until name <> '' ;
            writeln ('Tats{chlich ?') ;

repeat-statement = repeat statement {; statement}
                   until expression


     repeat        statement        until        boolean
                                                 expression
                       ,


WHILE STATEMENT

The while statement is similar to the repeat statement except the condition is checked at the top of the loop. If the boolean expression is true, then the statement is executed and the loop repeated.
,pg
,ce
REPETITIVE STATEMENTS

This will continue until the boolean expression is false. An infinite while loop is constructed by using the boolean constant "true" as the expression. 

The statement will not be executed at all if the expression is false when the while statement is entered.

Example : 
  var
    line = record
             link : ^line ;
             str : string
           end ;
    ptr : ^line ;
    .
    while ptr <> nil do
      begin
        writeln (ptr^.str) ;
        ptr := ptr^.link
      end ;

while-statement = while expression do statement

    while      boolean expression     do      statement


,ce
TRANSFER STATEMENTS

The transfer statements are used to modify the flow of control in a program where one of the standard conditional or repetitive statements is not suitable.

EXIT

The exit statement is used to "jump out of" loops. It can only be used to exit a for, repeat, or while loop. If executed inside a loop it will jump to the point at which the loop would terminate normally. For example :

   repeat
     statement1 ;
     statement2 ;
     if condition
       then
         exit ;
     statement3
   until condition ;
   statement            {this is the destination for the exit} 

If the optional integer parameter in parenthesis is used, then that will be the loop count. If you are nested 2 deep in loops then you can exit both loops by using : exit (2) . You cannot exit more levels of loops than you are currently in and you cannot use this to exit a block.

The exit statement is usually referred to as a "structured goto" and is preferable to a goto unless ISO standard code is desired.

exit-statement = exit [ ( unsigned-integer-constant ) ]

