grammarware / software-evolution

Software Evolution
MIT License
1 stars 0 forks source link

Data division parsing #7

Open LastAdequateCoder opened 6 months ago

LastAdequateCoder commented 6 months ago

For the data-division section it is said that "if neither the PICTURE nor the LIKE clause are used, such an entry defines a record". Does it mean that we can define a variable with no type? If so, how can the PICTURE be defined later in the program for such variable or will it always remain as 'no type'? image

grammarware commented 6 months ago

It means that it defines a composite data structure. As in,

01 R.
    03 F PICTURE IS 999.
    03 G PICTURE IS X.

Will define a record R with two fields: F OF R and G OF R.

DanielMocanovici commented 6 months ago

Follow up question for this one, would something like this be possible: image Hierarchy is preserved within the Record Variables but the level numeration differs from one Record to another (which I assume is fine as long as the levels themselves are in increasing order)

grammarware commented 6 months ago

Seems totally fine to me, except for two fields named N OF LAST.

Some dialects of COBOL (e.g., GnuCobol) will complain if the top level is not 01, but internal numeration can differ per record without consequences.

DanielMocanovici commented 6 months ago

Ye, about the first level, mainly the "01 Working-Storage Area". The paper mentions it is optional, so I assume the line is intended to just "set" the threshhold for levels beyond? Could it be "05 Working-Storage Area" meaning that all levels within the data have to be below 05

grammarware commented 6 months ago

In BabyCobol, it could be anything or even nothing at all, just go with your R/Last/Something/…, you can have multiple records and/or fields on level 01.

In COBOL, the DATA DIVISION consists of sections, and the one with what would have been "local variables", is called WORKING-STORAGE SECTION (without level). So for instance if you use an online COBOL compiler to check how some of your code behaves, you might need to add that one line just for your BabyCobol code to become valid COBOL code. So the top level record with that name in the paper is just a reference to that section.