grammarware / software-evolution

Software Evolution
MIT License
1 stars 0 forks source link

ALTER: identifier resolution #28

Closed Michael-Janssen-dev closed 4 months ago

Michael-Janssen-dev commented 4 months ago

For the ALTER statement, if the new target paragraph (so after the TO) is an identifier, is the value of that identifier evaluated at ALTER, or when the altered paragraph is performed?

In the following example:

...
DATA DIVISION.
    01 TARGET PICTURE IS X.
PROCEDURE DIVISION.
    MOVE "B" TO TARGET.
    ALTER A TO PROCEED TO TARGET.
    MOVE "C" TO TARGET.
    GO TO A.
A.
    GO TO A.
B. 
    DISPLAY "B" WITH NO ADVANCING.
    STOP.
C.
    DISPLAY "C" WITH NO ADVANCING. 

Would this display "B" or "C"?

grammarware commented 4 months ago

According to the definition of ALTER, both of its arguments are "procedure" (paragraph) names, so the easy answer is that your code should lead to a compiler error at the second line of PROCEDURE DIVISION. There is a version of GO TO where a developer can use a field name instead, but there is no such version for ALTER.

PS: can I haz access to https://github.com/Michael-Janssen-dev/baby-cobol-compiler-v3?

Michael-Janssen-dev commented 4 months ago

Thank you. My understanding was that "ProcedureName" in the grammar meant that it was an identifier containing a procedure name, or an actual procedure name, because the same symbol is used in the grammar for GO TO.

Access has been granted 👍🏻