In Rascal, why is it that when there is layout at the position of an optional part of a production, this causes ambiguity? E.g. "{ }"
is ambiguous as Start1
, while it parses fine as Start2
from the following grammar, which I would have expected to be exactly identical.
layout Layout = " "?;
start syntax Start1 = "{" "c"? "}";
start syntax Start2 = "{" "c" "}"
| "{" "}";
In addition, I would like to know if there is another way to represent Start2
without duplication than Start1
, that does not cause the same ambiguity.
Obviously there is no large amount of duplication in this code and Start2
is a good option here, but this is just an example. I am working with a grammar with many productions that contain three or four optional parts and in the last case the notation displayed in Start2
already requires duplicating the not-optional parts of the production 2^4=16 times, which really is troublesome in my opinion.