📄 fexpr.gml
字号:
.xt begin
.ix 'intrinsic function' CHAR
.ix CHAR
As an extension to the FORTRAN 77 language, &product supports the use
of the intrinsic function
.kw CHAR
in a character constant expression.
.exam begin
CHARACTER*6 HELLO, WORLD
PARAMETER (HELLO = 'Hello'//CHAR(0))
PARAMETER (WORLD = 'world'//CHAR(7))
PRINT *, HELLO, WORLD
END
.exam end
.xt end
.endlevel
.*
.section Relational Expressions
.*
.np
A relational expression is used to compare two arithmetic expressions
or two character expressions.
It is not possible to compare a character expression to an arithmetic
expression.
Evaluation of a relational expression produces a result of type
logical.
.*
.beglevel
.*
.section Relational Operators
.*
.np
.ix 'relational operator'
.ix operator relational
The following table lists the
.us relational operators
and the operation they perform.
.sr c0=&INDlvl+1
.sr c1=&INDlvl+12
.sr c2=&INDlvl+40
.mbox on &c0 &c1 &c2
Operator Relational Operation
.mbox
.LT. Less than
.LE. Less than or equal
.EQ. Equal
.NE. Not equal
.GT. Greater than
.GE. Greater than or equal
.mbox off
.*
.section Form of a Relational Expression
.*
.np
.ix 'relational expression'
.ix expression relational
The form of a
.us relational expression
is as follows.
.sr c0=&INDlvl+1
.sr c1=&INDlvl+26
.mbox on &c0 &c1
e1 relop e2
.mbox off
.synote 8
.mnote relop
is a relational operator.
.mnote e1, e2
are both arithmetic expressions or both character expressions.
.endnote
.*
.beglevel
.*
.section Arithmetic Relational Expressions
.*
.np
.ix 'arithmetic relational expression'
An
.us arithmetic relational expression
is a relational expression in which
.id e1
and
.id e2
are both arithmetic expressions.
An arithmetic relational expression has a value of true if the
operands satisfy the relation specified by the relational operator and
false otherwise.
.np
A complex operand is only permitted when using either the .EQ. or .NE.
relational operators.
.xt &product allows operands of type COMPLEX*16.
.*
.section Character Relational Expressions
.*
.np
.ix 'character relational expression'
.us Character relational expressions
are relational expressions whose operands are of type CHARACTER.
.ix 'collating sequence'
The value of a relation between character strings is established by
using the
.us collating sequence
of the processor character set.
The collating sequence is an ordering of the characters in the
processor character set.
Note, for example, that the EBCDIC character set has a different
collating sequence than that of the ASCII character set.
For example,
.id e1
is greater than
.id e2
if the value of
.id e1
follows the value of
.id e2
in the processor collating sequence.
The value of a character relational expression depends on the
collating sequence.
In the case of the .NE. and .EQ. operators, the collating sequence has
no effect.
.exam begin
IF( 'A' .LT. 'a' )THEN
PRINT *, 'The processor character set'
PRINT *, 'appears to be ASCII'
ELSE
PRINT *, 'The processor character set'
PRINT *, 'appears to be EBCDIC'
END IF
END
.exam end
.pc
The above example is a crude test for determining the character set
used on your processor.
.np
It is possible to have operands of unequal length.
In this case, the character string of smaller length is treated as if
blanks were padded to the right of it to the length of the larger
string.
The relational operator is then applied.
.endlevel
.endlevel
.*
.section Logical Expressions
.*
.np
Logical expressions are used to describe computations involving
operands whose type is LOGICAL
.xt or INTEGER
.ct , logical operators and left and
right parentheses.
The result of the computation is of type LOGICAL
.xt on
unless both operands are of type INTEGER in which case the result of
the computation is of type INTEGER.
.xt off
.*
.beglevel
.*
.section Logical Operators
.*
.np
.ix 'logical operator'
The following table lists the
.us logical operators
and the operation they perform.
.sr c0=&INDlvl+1
.sr c1=&INDlvl+12
.sr c2=&INDlvl+40
.mbox on &c0 &c1 &c2
Operator Logical Operation
.mbox
.NOT. Logical negation
.AND. Logical conjunction
.OR. Logical inclusive disjunction
.EQV. Logical equivalence
.NEQV. Logical non-equivalence
.XOR. Exclusive or
.mbox off
.np
The logical operator .NOT. is a unary operator; all other logical
operators are binary.
The following tables describe the result of each operator when it
is used with logical operands.
.* .mbox on 1 12 30
.sr c0=&INDlvl+1
.sr c1=&INDlvl+12
.sr c2=&INDlvl+30
.mbox on &c0 &c1 &c2
x .NOT. x
.mbox
true false
false true
.mbox off
.* .mbox on 1 9 17 30
.sr c0=&INDlvl+1
.sr c1=&INDlvl+9
.sr c2=&INDlvl+17
.sr c3=&INDlvl+30
.mbox on &c0 &c1 &c2 &c3
x y x .AND. y
.mbox
true true true
true false false
false true false
false false false
.mbox off
.mbox on &c0 &c1 &c2 &c3
x y x .OR. y
.mbox
true true true
true false true
false true true
false false false
.mbox off
.mbox on &c0 &c1 &c2 &c3
x y x .EQV. y
.mbox
true true true
true false false
false true false
false false true
.mbox off
.mbox on &c0 &c1 &c2 &c3
x y x .NEQV. y
................ x .XOR. y
.mbox
true true false
true false true
false true true
false false false
.mbox off
.np
Note that the operators .NEQV.
.xt on
and .XOR.
.xt off
perform the same logical operation.
.np
.xt begin
The following tables describe the result of the logical operators
when they are used with integer operands.
.* If one of the operands is of type LOGICAL, it is converted to INTEGER
.* type (.TRUE. is 1, .FALSE. is 0).
These operators apply to bits in the operand(s), hence we show only
the result of operations on individual bits.
The way to read the entries in the following tables is:
.autonote
.note
If the bit in "x" is 0 then the corresponding bit in ".NOT.x" is 1,
and so on.
.note
If the bit in "x" is 1 and the corresponding bit in "y" is 1 then
the corresponding bit in "x.AND.y" is 1, and so on.
.endnote
.xt end
.np
.* .mext on 1 12 30
.sr c0=&INDlvl+1
.sr c1=&INDlvl+12
.sr c2=&INDlvl+30
.mext on &c0 &c2 &c1
x .NOT. x
.mext
0 1
1 0
.mext off
.* .mext on 1 8 16 30
.sr c0=&INDlvl+1
.sr c1=&INDlvl+8
.sr c2=&INDlvl+15
.sr c3=&INDlvl+30
.mext on &c0 &c3 &c1 &c2
x y x .AND. y
.mext
1 1 1
1 0 0
0 1 0
0 0 0
.mext off
.mext on &c0 &c3 &c1 &c2
x y x .OR. y
.mext
1 1 1
1 0 1
0 1 1
0 0 0
.mext off
.mext on &c0 &c3 &c1 &c2
x y x .EQV. y
.mext
1 1 1
1 0 0
0 1 0
0 0 1
.mext off
.mext on &c0 &c3 &c1 &c2
x y x .NEQV. y
.............. x .XOR. y
.mext
1 1 0
1 0 1
0 1 1
0 0 0
.mext off
.np
Note that the operators .NEQV.
.xt on
and .XOR.
.xt off
perform the same mathematical operation on bits.
.np
As is the case with arithmetic operators, we must define rules in
order to evaluate logical expressions.
Again we define rules of precedence for logical operators which
dictate the evaluation sequence of logical expressions.
The following lists the logical operators in order of precedence.
.autopoint
.point
.li .NOT. (highest precedence)
.point
.li .AND.
.point
.li .OR.
.point
.li .EQV., .NEQV.
.xt and .XOR.
(lowest precedence)
.endpoint
.pc
For example, in the expression
.millust begin
A .OR. B .AND. C
.millust end
.pc
the .AND. operator has higher precedence than the .OR. operator so
.id B
and
.id C
are combined first using the .AND. operator.
The result is then combined with
.id A
using the .OR. operator.
.np
Parentheses can be used to alter the sequence of evaluation of logical
expressions.
If in the previous example we had written
.millust begin
(A .OR. B) .AND. C
.millust end
.pc
then
.id A
and
.id B
would have been combined first.
.*
.section Rules for Forming Logical Expressions
.*
.np
Logical primaries are the building blocks for logical expressions.
They are one of the following.
.autopoint
.point
logical
.xt or integer
constant
.point
symbolic logical
.xt or integer
constant
.point
logical
.xt or integer
variable reference
.point
logical
.xt or integer
array element reference
.point
logical
.xt or integer
function reference
.point
relational expression
.point
( logical
.xt or integer
expression )
.endpoint
.pc
As was done with arithmetic expressions, a grammar can be defined
which dictates the precedence relation among logical operators.
.np
The .NOT. logical operator has highest precedence.
.ix 'logical expression' 'logical factor'
We define a
.us logical factor
as:
.autopoint
.point
logical primary
.point
.li .NOT. logical primary
.endpoint
.np
Next in the precedence hierarchy is the .AND. operator.
.ix 'logical expression' 'logical term'
We define a
.us logical term
as:
.autopoint
.point
logical factor
.point
logical term .AND. logical factor
.endpoint
.pc
A logical term is simply a sequence of logical factors, each separated
by the .AND. operator.
Rule (2) specifies that the logical factors are combined from left to
right.
.np
Next is the .OR. operator.
.ix 'logical expression' 'logical disjunct'
We define a
.us logical disjunct
as:
.autopoint
.point
logical term
.point
logical disjunct .OR. logical term
.endpoint
.pc
A logical disjunct is simply a sequence of logical terms each
separated by the .OR. operator.
Rule (2) specifies that the logical terms are combined from left to
right.
.np
.ix 'logical expression'
.ix expression logical
A
.us logical expression
can now be defined as follows.
.autopoint
.point
logical disjunct
.point
logical expression .EQV. logical disjunct
.point
logical expression .NEQV. logical disjunct
.xt or logical expression .XOR. logical disjunct
.endpoint
.pc
A logical expression is therefore a sequence of logical disjuncts,
each separated by the .EQV. operator or the .NEQV.
.xt or .XOR.
operator.
Rules (2) and (3) indicate that logical disjuncts are combined from
left to right.
.np
Consider the following example.
.millust begin
A .OR. .NOT. B .AND. C
.millust end
.pc
Since the .NOT. operator has highest precedence we first logically
negate
.id B.
The result is then combined with
.id C
using the .AND. operator.
That result is then combined with
.id A
using the .OR. operator to form the final result.
.*
.section Logical Constant Expressions
.*
.np
.ix 'logical constant expression'
.ix expression 'logical constant'
A
.us logical constant expression
is a logical expression in which each primary is one of the following:
.autopoint
.point
logical constant
.point
symbolic logical constant
.point
a relational expression in which each primary is a constant expression
.point
( logical constant expression )
.endpoint
.np
The following are examples of a logical constant expression (assume
that
.id A,
.id B,
.id C
and
.id D
are arithmetic constants appearing in
.kw PARAMETER
statements).
.millust begin
.TRUE. .AND. .NOT. .FALSE.
'A' .LT. 'a'
A * B .GT. C * D
.millust end
.endlevel
.*
.section Evaluating Expressions
.*
.np
Four different types of operators have been discussed; arithmetic,
character, relational and logical.
It is possible to form an expression which contains all of these
operators.
Consider the following example.
.millust begin
A+B .LE. C .AND. X // Y .EQ. Z .AND. L
.millust end
.pc
where
.id A, B
and
.id C
are of numeric type,
.id X, Y
and
.id Z
are of type CHARACTER
and
.id L
is of type LOGICAL.
In this expression, + is an arithmetic operator, // is a character
operator, .EQ. is a relational operator and .AND. is a logical
operator.
Since we can mix these four types of operators, it is necessary to
define a precedence among these four classes of operators.
The following defines this precedence of operators.
.ix expression 'evaluation of'
.autopoint
.point
arithmetic operators (highest precedence)
.point
character operators
.point
relational operators
.point
logical operators (lowest precedence)
.endpoint
.pc
With this precedence any expression can now be evaluated without
ambiguity.
.*
.section Constant Expressions
.*
.np
.ix 'constant expression'
A
.us constant expression
is an arithmetic constant expression, a character constant expression
or a logical constant expression.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -