[ibm-enterprise-cobol] Unable to parse PERFORM UNTIL EXIT clause

Dear community managers,

I’ve noticed that the PERFORM UNTIL EXIT seems to be unknown to SonarScanner and cannot be parsed. While all other variations of PERFORM loops work, the relatively new EXIT keyword does not. This keyword/feature is part of the IBM Enterprise COBOL 6.4 release and was backported to 6.3 with APAR PH47372, the language reference an be found here.

A minimal working example would be as follows:

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    RI111.
       AUTHOR.        TEST.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       LINKAGE SECTION.
       PROCEDURE DIVISION.
      *-------------------------------------------------------------*
       RI111-MAIN SECTION.
           PERFORM UNTIL EXIT
               EXIT PERFORM CYCLE
           END-PERFORM
           CONTINUE.
       RI111-EXIT.
           EXIT.
      *-------------------------------------------------------------*
           EXIT PROGRAM.

Analyzing this sample program with SonarScanner CLI 7.0.2.4839 results in the following parsing error:

18:33:47.431 ERROR Unable to parse COBOL source file : <path-to-file>

Original contents starting from line 1 till line 18:
       IDENTIFICATION DIVISION.
       PROGRAM-ID.    RI111.
       AUTHOR.        TEST.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       LINKAGE SECTION.
       PROCEDURE DIVISION.
      *-------------------------------------------------------------*
       RI111-MAIN SECTION.
           PERFORM UNTIL EXIT
               EXIT PERFORM CYCLE
           END-PERFORM
           CONTINUE.
       RI111-EXIT.
           EXIT.
      *-------------------------------------------------------------*
           EXIT PROGRAM.


Preprocessed contents:
Parse error at line 11:

    1:  IDENTIFICATION DIVISION .
    2:  PROGRAM-ID . RI111 .
    3:  AUTHOR
    4:  ENVIRONMENT DIVISION .
    5:  DATA DIVISION .
    6:  WORKING-STORAGE SECTION .
    7:  LINKAGE SECTION .
    8:  PROCEDURE DIVISION .
   10:  RI111-MAIN SECTION .
   11:  PERFORM UNTIL EXIT
                     ^
   12:  EXIT PERFORM CYCLE
   13:  END-PERFORM
   14:  CONTINUE .
   15:  RI111-EXIT .
   16:  EXIT .
   18:  EXIT PROGRAM .
   19:  EOF

Hey @rr88!

Just to round out the report – what version fo SonarQube are you using? You can find this information in the footer of your instance.

Sorry @Colin, forgot about that.

SonarQube: v10.8.1 (101195)
SonarScanner: 7.0.2.4839

Hi @rr88,

Thank you for your reporting.
I added a ticket in our backlog (SONARCOBOL-1748) about fixing the parse error.

Best,

Andrea

Hello @Andrea_Guarino,

thank you for adding the ticket.

Do you or @Colin know of a way how we as users could avoid this parsing error? Is there a way to extend the parses in a custom plugin?
After looking at the decompiled Cobol SSLR it should be relatively trivial to add this language construct to the existing Cobol grammar but I’m unsure if there’s a way to do this on my own.

Hey @rr88

The only “workaround” right now would be to exclude the file from analysis. It’s not possible to extend the parsing capabilities outside of us updating the parser in the relevant analyzer.

1 Like