Hi Emanuele,
If you want to control newline placement, yes, you have to do it the
hard way by encoding, in the grammar, the specific places where newline
are allowed. The difficulty is to do it without introducing any ambiguity.
Trick: Chose between always matching newlines "before", or "after".
Then, stick to that choice in the whole grammar. The idea is to avoid:
p = r s ;
r = x newline*;
s = newline* y;
(The above grammar is ambiguous because the "newline", in the sentence
"x [newline] y", can be matched either in "r" or "s". )
Have fun!
Etienne
On 11-07-17 15:06, Emanuele Ianni wrote:
This is the main production in my grammar:
phrase =
{instruction} instr |
{complex_instruction} instr newline+ phrase? ;
Now, if someone just put a newline I'm getting the error it's
expecting an instruction. I could not set it as ignored token because
it's part of the grammar. Should I add a newline* in front of both
alternatives?
--
Etienne M. Gagnon, Ph.D.
SableCC: http://sablecc.org
_______________________________________________
SableCC-Discussion mailing list
[email protected]
http://lists.sablecc.org/listinfo/sablecc-discussion