,ll 6.6
,cs 10
,pl 66
,lm 0.2,0.5
,pn 1
,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
EXPRESSIONS

Expressions are a combination of one or more constants, variables, or functions separated by operators.

expression = simple-expression {(< | <= | = | <> | >= | > | in)
             simple-expression }
simple-expression = [(+ | -)] term {(eor | + | - | or) term}
term = factor {(* | / | ** | div | mod | and | << | >>) factor }
factor = (unsigned-constant | variable | ( expression ) |
         function-call | not factor | set-constructor)
variable = (variable-identifier | field-identifier) {( ^ |
           [ expression {, expression} ] | . field-identifier)}
function-call = function-identifier [( expression
                {, expression } ) ]
set-constructor = [ [ set-element {, set-element } ] ]
set-element = expression [.. expression]

 
Expression :
 
       simple
       expression
 
                          <    <=    =    <>    >=    >    in

 
Simple expression :
 
     +
 
             term
 
     -                    eor       +       -       or

 
Term :
 
      factor
 
                  *    /    **    div    mod    and    <<    >>



Variable :

     variable
     identifier            [      expression      ]

     field                            ,
     identifier
                           .      field identifier

                           ^

,pg
,ce
EXPRESSIONS


Factor :
 
          unsigned constant

 
          variable

 
          function identifier
 
                                  (    expression    )
 
                                           ,
 
          (       expression       )

 
          not       factor

 
          [                                             ]
 
                  expression    ..    expression
 
                                ,


The parts of an expression are evaluated Factor first, term, simple expression, and expression last; and within a part it is evaluated left to right. For all binary operators (except IN), the left and right expression parts must be of the same type, except that given values of signed or real, the smaller type will be converted to the larger type, and the result will be the larger type. Likewise, values of unsigned types will have the smaller type converted to the larger type. Signed and unsigned values are not compatible without explicit type conversion, except for constants as noted in chapter 4.

Binary operator compatibility table :
 
                          Expression type
 
Operator    Boolean Char signed unsigned Real Set Str Enumerated
 
<=  =       x    x    x   x   x    x    x    x   x   x
<>  >=
 
<  >        x    x    x   x   x    x    x        x   x
 
in          L    L    L   L                  R       L
 
div mod          x    x   x   x    x

*                x    x   x   x    x    x    x
 
**  /                                   x    
 
and or eor  x    x    x   x   x    x
 
<< >>            x    x   x   x    x 
 
+  -             x    x   x   x    x    x    x
 
not         x    x    x   x   x    x
 
Notes :
  L = Left operand.
  R = Right operand.
  x = both operands.
  Unary + or - are defined for signed and Real
  Pointers are allowed the same operations as unsigned.
  (1) : not available for longinteger or longhex.

,ce
ARITHMETIC EXPRESSIONS


Operator       Example                Meaning                    

   +            a + b       add a to b
   -            a - b       subtract b from a
   *            a * b       multiply a times b
   **          a ** b       raise a to the b power
   /            a / b       divide a by b
   div         a div b      divide a by b and truncate
   mod         a mod b      remainder after dividing a by b
   and         a and b      bitwise anding of a and b
   or          a or b       bitwise oring of a and b
   eor         a eor b      bitwise eoring of a and b
   not          not a       bitwise complement of a
   <<          a << b       shift a left b places (fill with 0)
   >>          a >> b       shift a right b places (fill with 0)

The addition and subtraction operators (+ and -) work on character, integer, longinteger, hex, longhex, real operands. Addition or subtraction of character or hex operands cannot generate an error (values wrap around 0). Addition or subtraction of integer values cannot generate an error unless the compiler S option is enabled.

The multiplication operator (*) will work on character, integer, longinteger, hex, longhex, and real operands. Multiplication of character operands cannot generate an error unless the compiler S option is enabled.

The power and division operators (** and /) work on real operands only. If either operand is an integer or longinteger, they will be converted to real before being processed. An attempted division by zero will yield an error if range checks are on, else a garbage result. The base operand of a power must not be negative.

The div and mod operators work on character, integer, longinteger, hex, and longhex operands. The right operand must not be zero.
,ce
ARITHMETIC EXPRESSIONS

The and, or, eor, and not operators work on boolean, character, integer, longinteger, hex, and longhex operands. All are bitwise except for the not operator for  boolean operands. For boolean not false becomes true, and true becomes false. Boolean eor is bitwise. The "and" and "or" operators use "short-circuit" evaluation for boolean operands. For the "and" operator, it will stop the evaluation as soon as a factor is false, since this determines the result of the entire expression as false. For the "or" operator, it will stop the evaluation as soon as a term is true, since this determines the result of the entire as true. This tends to speed up evaluation and in most cases will generate less code than full evaluation. It also allows constructs such as :

var ptr : ^integer ;

if (ptr <> nil) and (ptr^ = 5)

to be used safely, as the dereference will not be done if the pointer is nil. In a typical ladder network where you are checking for a number of sensors being on, time will be saved if you order your expressions based on chances of occurrence.

The shift left and shift right (<< and >>) operators work on character, integer, longinteger, hex, and longhex operands. The right operand is the shift count. Regardless of the direction of the shift, zeroes are shifted in. The effect of a negative shift count is undefined.

Except where otherwise noted above, the arithmetic operators allow you to mix integer, longinteger, and real operands. In the case of a mis-match, the smaller type is converted automatically to the larger type.

,ce
RELATIONAL EXPRESSIONS

The relational operators generate a boolean result based on a comparison of arithmetic or boolean operands.

Operator       Example                Meaning                    

   =            a = b       a is equal to b
   <            a < b       a is less than b
   >            a > b       a is greater than b
   <=          a <= b       a is less than or equal to b
   <>          a <> b       a is not equal to b
   >=          a >= b       a is greater than or equal to b

The relational operators work on boolean, character, integer, longinteger, hex, longhex, real, string, array, and record. String comparisons are done on a character by character basis using the ASCII ordering. If two strings have identical characters up until one of the strings runs out of characters, the shorter string is considered smaller.
,pg
,ce
SET EXPRESSIONS


Operator       Example                Meaning                    

   +            a + b       union of a and b, result of all
                            elements in either a or b
   -            a - b       difference of a and b, result of all
                            elements in a but not in b.
   *            a * b       intersection of a and b, result of
                            all elements in both a and b
   =            a = b       a is equal to b
   <>          a <> b       a is not equal to b
   <=          a <= b       elements in a are also in b
   >=          a >= b       elements in b are also in a
   in          k in a       ordinal k is in the set a

Operators +, -, and * require that both operands be sets and the result type will be a set. Operators =, <>, <=, and >= require that both operands be sets and the result type will be boolean. The in operator requires that the left operand be an ordinal and that the right operand be a set, returning a boolean result.

,ce
PRECEDENCE OF OPERATORS

The precedence of operators in Pascal is based on which syntax (expression, simple-expression, term, or factor) that the operator is located in. Within any precedence level evaluation is done from left to right. Below is a table of precedences going from highest to lowest :

syntax section    operators                  precedence          

factor            ( ) not                    1
term              * / ** div mod and << >>   2
simple-expression + - eor or                 3
expression        < <= = <> >= > in          4

,ce
VARIABLES

Variables may be either whole variables, or some part of the variable. Records may have individual fields accessed by following the record name with a period and the field name. Arrays may have individual elements accessed by indexing (index within brackets). Strings may be indexed by either an integer or byte expression in brackets, the result being a character. Devices and pointers may have their element or base type accessed by following the device or pointer name with a caret (^). 

These access methods may be nested in complex structures, for instance in :

type
  a = string [40] ;
  b = ^a ;
  c = record
        d : array [1..5] of b ;
        e : record
              f : integer ;
              g : real
            end ;
        h : a
      end ;
,ce
VARIABLES

var
  i : array [#1..#20] of c ;
  j : file of c ;

The following accesses can be made :

  i[#5].h          is a string [40] 
  i[10].e.f        is an integer
  j^.d[3]^         is a string [40]
