New member, TriAttack, has discovered a syntax compile error for the compute statement, see: [bd54dff202].
COMPUTE Num4 = (3/2)+3
Where Num4 is declared as PIC 9V9
Both the compiler and the parser in OCIDE say "Syntax Error, unexpected literal" on the line. However, when I input
COMPUTE Num4 = 3+(3/2)
The program works perfectly fine. Following the traditional order of operations, both lines should lead to the same value for Num4, 4.5, due to the parentheses.
The first compute statement will work if there are spaces on both sides of the plus sign.
Version 3.1.2.0
Discussion: bd54dff202
Discussion: About the Order of Operations of the COMPUTE Keyword
C:\GnuCOBOL>cobc -x compute1.cbl
compute1.cbl:18: error: syntax error, unexpected Literal
C:\GnuCOBOL>cobc -x compute2.cbl
C:\GnuCOBOL>compute2
4.5
3.5
OK, the issue is that this trips the part for signed numeric literals in the scanner, so the parser does not get
but
and therefore bails out with the unexpected literal at the end.
The workaround (also for old versions) is to add a space character after the + :
Note: this also applies to simpler computations:
COMPUTE Num4 = 2+3--> syntax errorCOMPUTE Num4 = 2+ 3--> fineRechecked: according to the standard that's fine:
Rechecked with MF: this recognizes the literal as verb; both this specific one and the 2+3 variant :)
Where do we stand with that?
... and my guess is that IBM will error similar.
So - just close this as "not a bug"?
On IBM the first program errors out the same.
The second program compiles with warnings , but does not display the decimal point in the answer.
If change 9v9 to 9.9 decimal is displayed.
OK, then all compiler agree with the standard here (apart from MF reasoning that as a statement) and we can close this; note that
cobc -std=ibmwill likely display identical as IBM (as that dialect disables "pretty printing).