Stop parsing if the parser panics.
--- a/calculator.c Mon Feb 08 03:59:18 2010 -0500
+++ b/calculator.c Mon Feb 08 04:29:05 2010 -0500
@@ -526,7 +526,7 @@
// !!! FIXME: when a rule reduces down later.
TokenData token = { ctx.token, ctx.tokenlen };
ParseCalculator(pParser, convert_to_lemon_token(&ctx), token, &ctx);
- } while (ctx.tokenval != TOKEN_EOI);
+ } while ((!ctx.isfail) && (ctx.tokenval != TOKEN_EOI));
ParseCalculatorFree(pParser, f, d);
}
--- a/calculator.lemon Mon Feb 08 03:59:18 2010 -0500
+++ b/calculator.lemon Mon Feb 08 04:29:05 2010 -0500
@@ -36,11 +36,14 @@
}
%parse_failure {
- fprintf(stderr,"Giving up. Parser is hopelessly lost...\n");
+ ctx->isfail = 1;
+ fprintf(stderr, "Giving up. Parser is hopelessly lost...\n");
+
}
%stack_overflow {
- fprintf(stderr,"Giving up. Parser stack overflow\n");
+ ctx->isfail = 1;
+ fprintf(stderr, "Giving up. Parser stack overflow\n");
}
// operator precedence (matches C spec)...