Those were backported into GnuCOBOL 3.2, but as no one passed the information (other than the NEWS entry), this is currently missing in the PG.
From the standard (2023):
A boolean operator specifies the type of boolean operation to be performed on one or two operands, for a unary operator or binary operator, respectively. The following are the boolean operators:
Binary boolean operators Meaning B-AND AND operation (boolean conjunction) B-OR Inclusive OR operation (boolean inclusive disjunction) B-XOR Exclusive OR operation (boolean exclusive disjunction)
Unary boolean operator Meaning B-NOT Negation operation
Boolean shift operators Meaning B-SHIFT-L SHIFT LEFT operation B-SHIFT-LC Circular SHIFT LEFT operation B-SHIFT-R SHIFT RIGHT operation B-SHIFT-RC Circular SHIFT RIGHT operation
The shift operators existed in other dialects before they were added to the standard, B-SHIFT-L
->B-LEFT
+ B-SHIFT-R
->B-RIGHT
; which is also supported by GnuCOBOL (if you don't use a strict dialect that does not have these reserved words). They operate on the binary value (no packing/unpacking done).
The binary operators can be used in computations or expressions. Both sides can be a numeric item or literal (including the special hex notations; see samples in tests/testsuite.src/run_extensions.at.
More quoting:
Evaluation of a boolean expression shall proceed as follows:
a) [... parentheses ...]
b) The precedence of operations at the same level of inclusiveness, is:
1st — negation (B-NOT)
2nd — conjunction (B-AND)
3rd — exclusive disjunction (B-XOR)
4th — inclusive disjunction (B-OR)
The precedence of boolean shift operations (B-SHIFT-L, B-SHIFT-R, B-SHIFT-LC and B-SHIFT-RC) is the same as that of the preceding operation, if any. If the boolean shift operation is not preceded by another operation, the precedence of that operation is the same as B-AND.
c) When the sequence of evaluation is not specified by parentheses, the evaluation of operations with the same precedence shall proceed from left to right.
@dilodilo Do you think we need more information here?
Wow, This is very cool.
I think a new Chapter should be inserted after 2.2.4. Arithmetic Expressions.
The new Chapter will be: 2.2.5 Boolean Expression.
Insert first of all the Syntax:
Boolean-Expression Syntax
[ Operand-1 ] { Boolean-Operator } Operand-2
and in this new chapter insert the exact text of your previous post
(be careful ... in your post there is a typo error:
B-SHIFT-L SHIFT
must beB-SHIFT-L
)I would then add the following table:
PS. Change also "Appendix C1 - Grouped Word Lists by feature and function"
I have prepared this test program.
Please, could verify that the results (see screenshot) are correct ?
Second test program for "SHIFT" operators.
@Vincent: in the programmers guide you entered the B-SHIFT-xx operators as intrinsic functions. I believe this is incorrect.
I ask Simon for confirmation.
For example B-SHIFT-L is an "operator" like B-AND for example it is not an intrinsic function.
The following program uses the B-SHIFT operators but I ask Simon if this example is correct.
I believe that B-SHIFT operators should work like B-NOT i.e. with only one operand.
However, if I put only one operand I get an error message from the compiler?!?!?
By putting two operands with the B-SHIFT-L operator for example, I get a result that doesn't match.
I think a clarification from Simon is needed.
So what is the state of the other four namely
B-AND
B-OR
B-XOR
B-NOT
These are currently in under functions so I "assume" that they are wrong as well and should only be in 2.2.4 -ish and removed from 8. Correct ?
.
There are no other boolean B-AND, B-OR ... in intrinsic functions chapter...
They are all operators
Please delete >> MORE text needed here? - PLACE HOLDER << and insert:
Operands must be defined as
PIC X(n) COMP-X
orPIC 9(n) COMP-5
.Last edit: Eugenio Di Lorenzo 2024-03-15
OK, its me mixing BIT-xxxx with B-xxx.
Please ignore.
On 15/03/2024 17:46, Eugenio Di Lorenzo wrote:
Ok thanks, now I think it's ok.
A small correction: the syntax you wrote
[ Operand-1 ] { Boolean-Operator } [ Operand-2 ]
it should be :
[ Operand-1 ] { Boolean-Operator } Operand-2
as Operand-2 must always be present.
Only Operand-1 can be missing when using the B-NOT operator which requires only Operand-2.
I'd suggest to specify a choice instead:
This way there are no optional operands and one does not have to make extra rules about B-NOT.
Nag, nag, nag - it is all done - well until the next complaint :)