grammarware / software-evolution

Software Evolution
MIT License
1 stars 0 forks source link

Like Clause. #9

Open DanielMocanovici opened 6 months ago

DanielMocanovici commented 6 months ago

A Like Clause is supposed to define a Variable of the same type as the mentioned variable and copy either its representation (if it is a Field) or its block of variables (if its a Record). However, how does one differentiate between 2 variables with the same name but on different levels (which I assume is possible)? e.g. image Here we can see that there are 2 variables N one on level 10 and one on level 09 which are both defined before the LIKE clause. Is this ambiguous and should thrown an error? The only difference between the 2 N's is the fact that the one on lv 10 can be represented as N of LAST3, however if we want our LIKE Clause to refer to the N on level 09, the only way would be to define it as N of LAST1 which is still ambigous. Do we by default assume that the first defined N would be the one we are refferring to?

grammarware commented 6 months ago

This example is ambiguous (and should produce an error). It is also possible to use (partial) quantification in the LIKE clauses: e.g., 10 N1 LIKE N OF LAST2. as the last line, would work just fine.

DanielMocanovici commented 6 months ago

image Is this possible then? for the like clause, since N500 of LAST4 is defined after

grammarware commented 6 months ago

In COBOL it is not:

The LIKE clause allows you to define the PICTURE, USAGE, SIGN, and FORMAT characteristics of a data item by copying them from a previously defined data item. It also allows you to make the length of the data item you define different from the length of the original item.

…so it should also not be allowed in BabyCobol.

Another example where LIKE clauses are extremely prominent is AppBuilder, a 4GL. However, there they only allow them in local declarations (PL/I-style DCL blocks in AppBuilder rules) which by definition are processed after the "bind files" (which define main data structures), so again it is only about backward references.