Expressions - OperandsOperands can be any of the following:
Each operand has a type associated with it that determines what operators can apply to it. For Integer constants, Real constants, Complex constants see Type declarations: basic types. Character and string constantsString constants are specified by enclosing a string of characters in either single or double quotes. A string constant with N characters has the type: ARRAY [0..N-1] OF CHAR String constants with exactly one character are also compatible with the CHAR type. String constants are compatible with ARRAYs that have an element type of CHAR. Note: for ease of interfacing with operating systems and other languages, string constants are always followed in memory by a byte containing the NUL character (0 decimal). A string constant with no characters (represented by two adjacent quotes, "") is allocated one byte and has the value NUL. If this string is passed to a procedure expecting an ARRAY OF CHAR, the upper bound will be zero, which indicates a string with one character. In this case, the one character is NUL. You can use set, array and record constants in expressions using the same syntax for the value as used in constant declarations. SET, ARRAY and RECORD value constructorsThis creates a constant value from expressions that cannot be computed at compile time. A value constructor can only be used in expressions that are part of a statement. SET, ARRAY and RECORD value constructors have the same syntax as SET, ARRAY and RECORD constants, however you can use non compile time values for any of the elements in the constructor. BITSET{x..y} If you use the BY keyword in an ARRAY value constructor, the BY repeat expression must still be a compile time constant. Variable designatorsA variable designator refers to the current value of a variable. The syntax of a variable designator is: [modulename.]variablename{qualifier} If the modulename is specified, the variablename exported from that module is used. Otherwise, the variablename is interpreted in the current scope. Qualifier is: [ field | subscript | dereference | subarray | coercion ] Field qualifier The field qualifier is specified by: designator.identifier The field qualifier can be applied to a variable designator that refers to a record type. The new designator refers to the field of the record named by the identifier. Subscript qualifierThe subscript qualifier is specified by: designator[expression{,expression}] The subscript qualifier can be applied to a variable designator that is an array type. The resulting designator refers to the component of the array selected by the index values specified by the expressions. An expression of the form: A[e1, e2] is equivalent to: A[e1][e2] Dereference qualifierDereference qualifierThe dereference qualifier is specified by: designator^ The dereference qualifier can be applied to any designator that refers to a pointer type. The resulting designator refers to the object pointed to by the pointer variable. Procedure designatorsA procedure designator is simply the name of the procedure. A procedure designator refers to the address of the procedure and can only be passed as a parameter or assigned to a procedure variable. Function callsA procedure designator followed by parentheses is a function call. The procedure must be a function procedure; that is, its declaration must include a return type. A function call is specified by: FunctionName([expression{,expression}]) The list of expressions are the actual parameters of the function. The actual parameters are matched in order with the formal parameters. The requirements for the actual parameters depend on how the formal parameter was declared:
Formal parameter types are discussed in depth in the Procedures topic in this document. The value of a function call is the value returned on the return statement in the function procedure. Type castYou can force an expression to be interpreted as a type other than its usual type by using a type cast. A type cast takes the following form: CAST(TypeName, expression) The expression is evaluated, then forced to be interpreted as the type specified by TypeName. No conversion of data is done by type transfers. The raw data is interpreted as the new type. The CAST function is imported from the SYSTEM module. This means that type transfers are dependent on the data representation used by an implementation, and are therefore not transportable. For this reason, type conversion procedures are preferred when applicable. See the Standard Procedures chapter of this manual for information about type conversion procedures. Type transfers from a shorter to a longer type are allowed, however a warning is generated because the excess bits are undefined. Example: VAR The value written is 22, because the BITSET has bits 1, 2, and 4 set. When interpreted as a CARDINAL this makes the number 22. Source:
|