Stop parsing if the parser panics. calculator-experiment
authorRyan C. Gordon <icculus@icculus.org>
Mon, 08 Feb 2010 04:29:05 -0500
branchcalculator-experiment
changeset 820 fd001ff71c65
parent 818 6f893a2224d8
child 821 ecf9f8157ada
Stop parsing if the parser panics.
calculator.c
calculator.lemon
--- 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)...