adMartem
Hi. Sorry to be a bit slow getting back to you on this. The last week or so has been rather unusual though. On Monday, I flew back to Spain from England, and between my last few days in England and then getting home and having other things to deal with...
Well, anyway, it seems like what you are running into is a bug. Basically, here:
Device# :
<TAPE> | <INPUT_OUTPUT> | <OUTPUT> | <INPUT> | <DISPLAY> | DeviceName =>||
;
It is not generating a full scanahead predicate for the DeviceName=>||
expansion and clearly it should.
Basically, one could say that if you're at a choice point, the logic of whether to go into that sub-expansion is either:
- Just LL(1), i.e. just checking if the next token is in the expansion's "first set"
- An actual generated predicate routine that is more sophisticated than that.
The problem is that it's just using the first type of logic when it should be doing the second one. It's reasoning that the expansion in question consumes exactly one token so it should use the first set logic, even though there is semantic predicate sort of logic inside the expansion that should be taken into account.
Actually, properly considered, this is a rather glaring bug. And actually, I was just playing with this a little and noticed that, for example, if you rewrite the DeviceName production like:
DeviceName# :
<MERGE> // Sort-merge storage device
| <SORT> // Sort-merge storage device
| <SORT_MERGE> // Sort-merge storage device
| <TAPE> // Input-output device or file
| SCAN 0 {isDeviceName()}# => <COBOL_WORD> [<DISPLAY>] // Added an optional token
;
then since the DeviceName production potentially consumes 2 tokens, it generates the appropriate code. (You could try it.) The problem is that, as it was written before, always consuming exactly one token, it (incorrectly) always just used the first set logic.
There was another bug very similar to this reported a month ago, and it was based on a similar problem. See here: https://github.com/javacc21/javacc21/issues/188#issuecomment-1138926324
But that was resolved somehow but there is still this problem with what you are writing here. Well, I'll look into this and fix it shortly. Stay tuned...