diff --git a/MathEval/parser.cpp b/MathEval/parser.cpp index 97048d87553f71e936e60ce33d17cd85b63c175b..8944f5f000654e4afd0712674576906cd4526aa0 100644 --- a/MathEval/parser.cpp +++ b/MathEval/parser.cpp @@ -54,7 +54,14 @@ int yyerror (char *s); is generated by scanner generator). */ int yylex (void); -#line 41 "parser.y" +/* Function used to flush the internal flex buffer when we exit + prematurely (i.e., in case of a parse error) so that the next time + we call the scanner, all is nicely reset. Without this, the + behaviour of the next call after an error is unpredictable. */ +int force_buffer_flush(void); + + +#line 48 "parser.y" #ifndef YYSTYPE typedef union { Node *node; @@ -128,8 +135,8 @@ static const short yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const short yyrline[] = { - 0, 64, 72, 75, 78, 82, 86, 90, 94, 98, - 102, 106 + 0, 71, 78, 81, 84, 88, 92, 96, 100, 104, + 108, 112 }; #endif @@ -915,76 +922,75 @@ yyreduce: switch (yyn) { case 1: -#line 64 "parser.y" +#line 71 "parser.y" { matheval_root = yyvsp[-1].node; - yyerrok; return 1; ; break;} case 2: -#line 72 "parser.y" +#line 78 "parser.y" { yyval.node = yyvsp[0].node; ; break;} case 3: -#line 75 "parser.y" +#line 81 "parser.y" { yyval.node = yyvsp[0].node; ; break;} case 4: -#line 78 "parser.y" +#line 84 "parser.y" { /* Create addition binary operator node. */ yyval.node = node_create ('b', '+', yyvsp[-2].node, yyvsp[0].node); ; break;} case 5: -#line 82 "parser.y" +#line 88 "parser.y" { /* Create subtraction binary operator node. */ yyval.node = node_create ('b', '-', yyvsp[-2].node, yyvsp[0].node); ; break;} case 6: -#line 86 "parser.y" +#line 92 "parser.y" { /* Create multiplication binary operator node. */ yyval.node = node_create ('b', '*', yyvsp[-2].node, yyvsp[0].node); ; break;} case 7: -#line 90 "parser.y" +#line 96 "parser.y" { /* Create division binary operator node. */ yyval.node = node_create ('b', '/', yyvsp[-2].node, yyvsp[0].node); ; break;} case 8: -#line 94 "parser.y" +#line 100 "parser.y" { /* Create minus unary operator node. */ yyval.node = node_create ('u', '-', yyvsp[0].node); ; break;} case 9: -#line 98 "parser.y" +#line 104 "parser.y" { /* Create exponentiation unary operator node. */ yyval.node = node_create ('b', '^', yyvsp[-2].node, yyvsp[0].node); ; break;} case 10: -#line 102 "parser.y" +#line 108 "parser.y" { /* Create function node. */ yyval.node = node_create ('f', yyvsp[-3].record, yyvsp[-1].node); ; break;} case 11: -#line 106 "parser.y" +#line 112 "parser.y" { yyval.node = yyvsp[-1].node; ; @@ -1222,7 +1228,7 @@ yyreturn: #endif return yyresult; } -#line 111 "parser.y" +#line 117 "parser.y" int yyerror(char* s) @@ -1230,5 +1236,6 @@ int yyerror(char* s) /* Indicate parsing error through appropriate flag and stop parsing. */ matheval_ok = 0; + force_buffer_flush(); return 0; } diff --git a/MathEval/parser.y b/MathEval/parser.y index 7c3d250b11ac510474b1de58d6b73bf4a6e9cfe5..10db82c2c726d5c90e48f21840fd68320657d078 100644 --- a/MathEval/parser.y +++ b/MathEval/parser.y @@ -35,6 +35,13 @@ int yyerror (char *s); /* Function used to tokenize string representing function (this function is generated by scanner generator). */ int yylex (void); + +/* Function used to flush the internal flex buffer when we exit + prematurely (i.e., in case of a parse error) so that the next time + we call the scanner, all is nicely reset. Without this, the + behaviour of the next call after an error is unpredictable. */ +int force_buffer_flush(void); + %} /* Parser semantic values type. */ @@ -63,7 +70,6 @@ int yylex (void); input : expression '\n' { matheval_root = $1; - yyerrok; return 1; } ; @@ -115,5 +121,6 @@ int yyerror(char* s) /* Indicate parsing error through appropriate flag and stop parsing. */ matheval_ok = 0; + force_buffer_flush(); return 0; } diff --git a/MathEval/scanner.cpp b/MathEval/scanner.cpp index 67e95880ad72f84f8e11308a8f77ccf583c61a39..004b773591e7d1fe89979046efa110f41e2c559f 100644 --- a/MathEval/scanner.cpp +++ b/MathEval/scanner.cpp @@ -20,7 +20,7 @@ /* A lexical scanner generated by flex */ /* Scanner skeleton version: - * $Header: /cvsroot/gmsh/MathEval/scanner.cpp,v 1.3 2004-05-12 18:38:44 geuzaine Exp $ + * $Header: /cvsroot/gmsh/MathEval/scanner.cpp,v 1.4 2004-05-12 18:57:48 geuzaine Exp $ */ #define FLEX_SCANNER @@ -1687,7 +1687,7 @@ int main() #undef mewrap -int mewrap() {return 1;} +int mewrap() { return 1; } static int input_from_string (char *buffer, int max_size) { @@ -1704,3 +1704,5 @@ static int input_from_string (char *buffer, int max_size) return count; } + +int force_buffer_flush() { YY_FLUSH_BUFFER; } diff --git a/MathEval/scanner.l b/MathEval/scanner.l index 8c6977fd41b83d043d1f58c0cdcd7b3ceacae71c..b060e2b5e142ce04d8c2d89b17cbe1276c499873 100644 --- a/MathEval/scanner.l +++ b/MathEval/scanner.l @@ -107,7 +107,7 @@ identifier [a-zA-Z\_][a-zA-Z0-9\_]* #undef mewrap -int mewrap() {return 1;} +int mewrap() { return 1; } static int input_from_string (char *buffer, int max_size) { @@ -124,3 +124,5 @@ static int input_from_string (char *buffer, int max_size) return count; } + +int force_buffer_flush() { YY_FLUSH_BUFFER; }