Hi,
I noticed GnuCobol fails to handle these very-specific "short" picture-strings:
01 P1 PIC 9$ .
01 P2 PIC 9$+ .
GnnuCobol complains with the following error:
error: a leading currency symbol cannot follow 9
I tracked down the problem, which seem to reside in the char_to_precedence_idx function (in tree.c). To check whether the currency symbol is leading or trailing, the code checks for the two first or two last character of the picture string. Here is the relevant part of the code:
if (first_sym || second_sym) {
return 7;
} else if (penultimate_sym || last_sym) {
return 8;
} else {
/* Fudge char type - will still result in error */
return 7;
}
This is fine for picture strings whose length is >= 4, but becomes ambiguous otherwise : with a length or 3, the second is also the penultimate, and with a picture of length 2, the first is also the penultimate and the second is also the last.
In case of length = 2, this can be easily solved by giving priority to first/last over second/penultimate, but I'm not sure how to disambiguate when length = 3, as illustrated by these two picture-strings:
01 P2 PIC 9$+ .
01 P3 PIC +$9 .
Note that GnuCobol correctly parses the second one, since it currently prioritize first/second over penultimate/last.
It seems we somehow have to consider the type of character that precedes or follows the currency sign in order to determine if it is leading or trailing.
Any opinion about this ?
Hm, if this is only for the check we can double a single
9to work around that, no?Looks a bit strange and needs a comment, but if we solve this ambiguity by this easily that way...
Last edit: Simon Sobisch 2024-01-09
This is resolved with the commit I'm doing today
Is a test case needed for:
01 P3 PIC $+9 .Or is that already handled correctly?
checked in with [r5306]
Related
Commit: [r5306]