TypeCobolTeam / TypeCobol

TypeCobol is an Incremental Cobol parser for IBM Enterprise Cobol 6 for zOS syntax. TypeCobol is also an extension of Cobol 85 language which can then be converted to Cobol85.
Other
78 stars 26 forks source link

Invalid precedence of operators when building abbreviated relation conditions #2640

Open fm-117 opened 3 months ago

fm-117 commented 3 months ago

Describe the bug Following #2083, it appears that the syntax is correctly supported but the semantics of abbreviated expressions is wrong. See the code example.

To Reproduce

       IDENTIFICATION DIVISION.
       PROGRAM-ID. TCOMFL06.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 A PIC X.
       01 B PIC X.
       01 C PIC X.
       01 D PIC X.
       01 E PIC X.
       PROCEDURE DIVISION.
           IF (A = B OR C AND D = E)
              DISPLAY "with abbreviated syntax"
           END-IF
           IF (A = B OR (A = C AND D = E))
              DISPLAY "with explicit parentheses"
           END-IF
           IF (A = B OR A = C AND D = E)
              DISPLAY "with implicit operator precedence rules"
           END-IF
           GOBACK
           .
       END PROGRAM TCOMFL06.

Expected behavior The 3 conditions are identical. While the parser gives a correct result for the last two, the first is incorrect:

{A B EqualTo A C EqualTo OR D E EqualTo AND} --> KO
{A B EqualTo A C EqualTo D E EqualTo AND OR} --> OK
{A B EqualTo A C EqualTo D E EqualTo AND OR} --> OK

Technical TODO

How to test automatically TODO Check if we already have tests on conditions