Assignments and expressions

Language reference ›› Statements ››
Parent Previous Next

assignment = variable ":=" expression .
expression = ( relation | term ) { ( "+" | "-" ) term } .
relation = bool-expression "(" bool-op bool-expression ")" .
term = factor { ( "*" | DIV | "/" | MOD ) factor } .
factor = { "+" | "-" } expression | variable { "." bit } | function-call .
bool-expression = expression { relop expression } .
relop = "=" | "<>" | "<" | ">" | "<=" | ">=" | IN .
bool-op = AND | OR | XOR | SHL | SHR .
function-call = function-name [ function-args ] .

PMP parses expressions containing constants, variables and function calls and obeys the normal Pascal rules of precedence.  

In non-strict mode PMP has no type checking for simple variables, so any combination of types may be used (possible truncation will produce a warning).

Boolean variables or bits are internally used as single bits but if used in non-boolean expressions they are converted by an implicit ORD to byte values of TRUE (1) or FALSE (0).

In non-strict mode, for boolean expressions any value other than zero is treated as TRUE, so this construction is allowed, even for non-boolean variables:


IF Variable THEN


Would generate the same code as:


IF Variable <> 0 THEN


The use of simple constants may be optimized by PMP when “always true” or “always false” condition may be computed:

A "while <Constant expression evaluated to false> do <block>" will not generate any code.

A "if <Constant expression evaluated to false> then <block>" will not generate any code, if an "else <block>" exists, only this "else <block>" will be generated.

A "while <Constant expression evaluated to true> do <block>" will generate only <block> that loops forever.

This may help for conditional compilation if configuration constants are used (may be used the same way as $IFDEF/$ENDIF blocks).

In PMP two boolean constants are predefined: TRUE = 1 and FALSE = 0. Since there is no type checking on booleans in non-strict mode, either TRUE and FALSE or 0 and 1 may be used for booleans.