CONSTANT - handling of constants in MAP.

Description:

Standard Pascal is very restrictive about constants, and does not allow constant expressions in the declaration of other constants or in other places where a constant value is required such as case labels, value ranges in type declarations, etc. MAP attempts to alleviate this problem by evaluating constant expressions in the CONST section, and replacing each expression with its value. Since Pascal will accept constant expressions where a constant is required, this feature is not as necessary as it is in other Pascal implementations. However, MAP accepts a wider range of constant expressions than the compiler does, so the feature is still useful. In particular, MAP will allow you to construct constant strings from other constant strings. It also recognizes some of the standard functions and predefines some constants for the current date and time.

MAP allows you to add a new MCONST section to your programs and procedures. Constants defined in the MCONST section do not appear in the output Pascal program, but may be used in constant expressions when defining other constants in the CONST section. Constants defined in the MCONST section may also be used to control conditional compilation (see "expl map codeif").

Constant expressions may contain any of the operators listed below in decreasing order of precedence. Parentheses may be used to alter precedence as usual.

Functions:      name(argument)  -- see below
Unary:          not ~ -
Multiplying:    and / * div mod max min
Adding:         or + -
Relating:       < <= = >= > <> <> ~=
Concatenating:  blank

All operators except "min", "max" and blank have the same meaning as in Pascal. "min" and "max" are binary operators (much like "div"), and may be used with real or integer operands. The result will be of the same type as the operands.

The blank operator, denoting concatenation, may only be used with operands that are string or character constants; the operator produces a string constant as a result.

MAP recognizes the standard Pascal functions abs, arctan, chr, cos, exp, ln, odd, ord, round, sin, sqr and trunc in constant expressions. In addition, MAP supports two more functions: "length(string)" and "stringof(integer)". "length" takes a string or character constant and returns its length. Character constants will have a length of 1. "stringof" takes an integer and returns its decimal represention as a string or character constant. No leading blanks are supplied, but a minus is included if the argument is negative. Note that under the rules of Pascal, if the argument is a number in the range of 0-9 then the result will be a character constant rather than a string. If "t" is an integer constant, "length(stringof(t))" will be the number of print positions necessary to output "t".

MAP supplies several predefined constants for use in constant expressions. These predefined constants are not passed on to the output Pascal program however, and are not generally available in the program text outside constant expressions in the CONST or MCONST sections. To pass a predefined constant to Pascal, the user must define a user constant and place the predefined constant on the right hand side of the "=" in the constant definition. The same rule applies to user constants defined in the MCONST section.

The predefined constants are

Constant     Type and Value
--------     --------------
 true        boolean, true
 false       boolean, false
 date        packed array [1..8] of char, 'mm/dd/yy'
 mm          packed array [1..2] of char, 'mm'
 dd          packed array [1..2] of char, 'dd'
 yy          packed array [1..2] of char, 'yy'
 time        packed array [1..8] of char, 'hh:mm:ss'
 maxint      integer, 34359738367
 minint      integer,-34359738368 = -maxint-1

Copyright © 1996, Thinkage Ltd.