Menu

Wrong compiler error message ?

2025-09-12
2025-09-14
  • Eugenio Di Lorenzo

    Another small program where the error is clear: there are two level 78 fields with the same name.
    In this case, the error is also easy to find.
    However, the original program was much longer and more complex, and the fact that there were two fields with the same name (one of them inside a copy file) was not easy to spot.
    The problem I want to point out is that the compiler message
    syntax error, unexpected Literal, expecting Identifier
    seems to me completely misleading compared to the real error (a duplicate field).

           >>SOURCE FORMAT IS FREE
    IDENTIFICATION DIVISION.
    PROGRAM-ID.   TEST101.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    77  SET-MOUSE-FLAGS            PIC   9(04).
    01  MOUSE-FLAGS      PIC 9(04).
    78  SET-AUTO-MOUSE-HANDLING    VALUE 1.
    78  SET-AUTO-MOUSE-HANDLING    VALUE 1.
    PROCEDURE DIVISION.
      COMPUTE MOUSE-FLAGS = SET-AUTO-MOUSE-HANDLING
                          + SET-LEFT-DOWN   + SET-MIDDLE-DOWN   + SET-RIGHT-DOWN
                          + SET-LEFT-UP     + SET-MIDDLE-UP     + SET-RIGHT-UP
                          + SET-LEFT-DOUBLE + SET-MIDDLE-DOUBLE + SET-RIGHT-DOUBLE
                          + SET-MOUSE-MOVE
      SET environment     "COB_MOUSE_FLAGS"   to MOUSE-FLAGS
      GOBACK.
    

    This is the only compiler message:

    C:\OpenCobolIDE\GC20base2\bin\cobc.exe -x -o bin\TEST101.exe -std=default -TGCLISTING.TXT -Wall -Xref -debug -fdebugging-line -fec=EC-ALL -frelax-syntax-checks -fstop-error-statement=ok -ftrace -ftsymbols -free -lpdcurses TEST101.COB
    TEST101.COB:9: error: syntax error, unexpected Literal, expecting Identifier
    7 | 01 MOUSE-FLAGS PIC 9(04).
    8 | 78 SET-AUTO-MOUSE-HANDLING VALUE 1.
    9 > 78 SET-AUTO-MOUSE-HANDLING VALUE 1.
    10 | PROCEDURE DIVISION.
    11 | COMPUTE MOUSE-FLAGS = SET-AUTO-MOUSE-HANDLING

    And there are also some undefined fields but this is not reported as an error...

     
    • Eugenio Di Lorenzo

      Can anyone give me a feedback on this rather ambiguous compiler message?

       
  • Simon Sobisch

    Simon Sobisch - 2025-09-14

    Have a look at [feature-requests:#464] for the details - in short: the current preparser inserts the recognized literals before the parser sees that, allow easy recognition of type mismatches and optimizations. It could and should be changed, but that's still a work someone needs to be done.

     

    Related

    Wish List: #464

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.