-
Notifications
You must be signed in to change notification settings - Fork 191
Description
Consider the following re2c source (1.re):
/*!re2c
<c1> [^]+ "a" {}
<c1> "b" {}
<c2> "d" {}
<c2> "ddd" {}
*/
Build and grep YYMARKER and condition borders:
$ re2c -c 1.re | grep -E "YYMARKER|yyc_"
case yycc1: goto yyc_c1;
case yycc2: goto yyc_c2;
yyc_c1:
yych = *(YYMARKER = ++YYCURSOR);
YYMARKER = ++YYCURSOR;
yyc_c2:
YYCURSOR = YYMARKER;
yych = *(YYMARKER = ++YYCURSOR);
Condition c2 needs YYMARKER (it backups and restores YYCURSOR). Condition c1 doesn't need YYMARKER (it never restores YYCURSOR, but backups it).
With HEAD the bug emerges even without '-c':
/*!re2c
[^]+ "a" {}
"b" {}
*/
Build and grep:
$ re2c 1.re | grep "YYMARKER"
yych = *(YYMARKER = ++YYCURSOR);
YYMARKER = ++YYCURSOR;
Note: It may be not so obvious that YYMARKER is redundant. One may think that re2c should have generated code that restores YYCURSOR (that the real error is not redundant backup, but the lack of restore). That's not true: in this case, though rules overlap, longer rule always succeeds (so there's no need to backup shorter rule match). When I say "longer rule always succeeds" I'm pretty aware that input string may end unexpectedly. In this case either YYFILL will supply enough characters for the longer rule to succeed or YYFILL will not return and the shorter rule match will be discarded anyway.
Original comment by: skvadrik