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 25 forks source link

Wrong syntax tree for nested programs #2319

Open fm-117 opened 2 years ago

fm-117 commented 2 years ago

Describe the bug In some cases, nested program is not correctly attached to its parent program but to a paragraph instead.

To Reproduce

       IDENTIFICATION DIVISION.
       PROGRAM-ID. MainPgm.
       procedure division.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. Nested1.
       data division.
       local-storage section.
       01 Var1             pic X.

       procedure division.
           if ( Var1 = "A" )
                set

       end program Nested1.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. Nested2.
       procedure division.
           goback
           .
       end program Nested2.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. Nested3.

       END PROGRAM Nested3.

       END PROGRAM MainPgm.

Expected behavior Correct AST, parent node of a NestedProgram is expected to be a Program object.

Technical

How to test automatically Standard program test.

fm-117 commented 1 year ago

Looks like an incremental bug. Could not reproduce bug with private source code captured by logging...

fm-117 commented 1 year ago

This can be reproduced with following source code:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. TCOFM117.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 Group1.
           05 Array1 OCCURS 60 TIMES
                              INDEXED BY MyIndex.
             10 Array1-Elt1             PIC X(03).

       PROCEDURE DIVISION.
           SEARCH Array1 VARYING MyIndex
           at end

           END-SEARCH
           .

       IDENTIFICATION DIVISION.
       PROGRAM-ID. Nested.
       END PROGRAM Nested.
       END PROGRAM TCOFM117.

Same problem as in #2434 and fixed with #2436.

Keeping the issue open as the bug could happen with other unsupported constructs.

efr15 commented 1 year ago

Issue has occurred again with parser 1.6.5 (additional information available in our internal issue tracking system WI 214934).