Skip to content
Snippets Groups Projects
Commit 19773f88 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

force flex buffer flush after an error
parent 6974762c
No related branches found
No related tags found
No related merge requests found
...@@ -54,7 +54,14 @@ int yyerror (char *s); ...@@ -54,7 +54,14 @@ int yyerror (char *s);
is generated by scanner generator). */ is generated by scanner generator). */
int yylex (void); 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 #ifndef YYSTYPE
typedef union { typedef union {
Node *node; Node *node;
...@@ -128,8 +135,8 @@ static const short yyrhs[] = ...@@ -128,8 +135,8 @@ static const short yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const short yyrline[] = static const short yyrline[] =
{ {
0, 64, 72, 75, 78, 82, 86, 90, 94, 98, 0, 71, 78, 81, 84, 88, 92, 96, 100, 104,
102, 106 108, 112
}; };
#endif #endif
...@@ -915,76 +922,75 @@ yyreduce: ...@@ -915,76 +922,75 @@ yyreduce:
switch (yyn) { switch (yyn) {
case 1: case 1:
#line 64 "parser.y" #line 71 "parser.y"
{ {
matheval_root = yyvsp[-1].node; matheval_root = yyvsp[-1].node;
yyerrok;
return 1; return 1;
; ;
break;} break;}
case 2: case 2:
#line 72 "parser.y" #line 78 "parser.y"
{ {
yyval.node = yyvsp[0].node; yyval.node = yyvsp[0].node;
; ;
break;} break;}
case 3: case 3:
#line 75 "parser.y" #line 81 "parser.y"
{ {
yyval.node = yyvsp[0].node; yyval.node = yyvsp[0].node;
; ;
break;} break;}
case 4: case 4:
#line 78 "parser.y" #line 84 "parser.y"
{ {
/* Create addition binary operator node. */ /* Create addition binary operator node. */
yyval.node = node_create ('b', '+', yyvsp[-2].node, yyvsp[0].node); yyval.node = node_create ('b', '+', yyvsp[-2].node, yyvsp[0].node);
; ;
break;} break;}
case 5: case 5:
#line 82 "parser.y" #line 88 "parser.y"
{ {
/* Create subtraction binary operator node. */ /* Create subtraction binary operator node. */
yyval.node = node_create ('b', '-', yyvsp[-2].node, yyvsp[0].node); yyval.node = node_create ('b', '-', yyvsp[-2].node, yyvsp[0].node);
; ;
break;} break;}
case 6: case 6:
#line 86 "parser.y" #line 92 "parser.y"
{ {
/* Create multiplication binary operator node. */ /* Create multiplication binary operator node. */
yyval.node = node_create ('b', '*', yyvsp[-2].node, yyvsp[0].node); yyval.node = node_create ('b', '*', yyvsp[-2].node, yyvsp[0].node);
; ;
break;} break;}
case 7: case 7:
#line 90 "parser.y" #line 96 "parser.y"
{ {
/* Create division binary operator node. */ /* Create division binary operator node. */
yyval.node = node_create ('b', '/', yyvsp[-2].node, yyvsp[0].node); yyval.node = node_create ('b', '/', yyvsp[-2].node, yyvsp[0].node);
; ;
break;} break;}
case 8: case 8:
#line 94 "parser.y" #line 100 "parser.y"
{ {
/* Create minus unary operator node. */ /* Create minus unary operator node. */
yyval.node = node_create ('u', '-', yyvsp[0].node); yyval.node = node_create ('u', '-', yyvsp[0].node);
; ;
break;} break;}
case 9: case 9:
#line 98 "parser.y" #line 104 "parser.y"
{ {
/* Create exponentiation unary operator node. */ /* Create exponentiation unary operator node. */
yyval.node = node_create ('b', '^', yyvsp[-2].node, yyvsp[0].node); yyval.node = node_create ('b', '^', yyvsp[-2].node, yyvsp[0].node);
; ;
break;} break;}
case 10: case 10:
#line 102 "parser.y" #line 108 "parser.y"
{ {
/* Create function node. */ /* Create function node. */
yyval.node = node_create ('f', yyvsp[-3].record, yyvsp[-1].node); yyval.node = node_create ('f', yyvsp[-3].record, yyvsp[-1].node);
; ;
break;} break;}
case 11: case 11:
#line 106 "parser.y" #line 112 "parser.y"
{ {
yyval.node = yyvsp[-1].node; yyval.node = yyvsp[-1].node;
; ;
...@@ -1222,7 +1228,7 @@ yyreturn: ...@@ -1222,7 +1228,7 @@ yyreturn:
#endif #endif
return yyresult; return yyresult;
} }
#line 111 "parser.y" #line 117 "parser.y"
int yyerror(char* s) int yyerror(char* s)
...@@ -1230,5 +1236,6 @@ int yyerror(char* s) ...@@ -1230,5 +1236,6 @@ int yyerror(char* s)
/* Indicate parsing error through appropriate flag and stop /* Indicate parsing error through appropriate flag and stop
parsing. */ parsing. */
matheval_ok = 0; matheval_ok = 0;
force_buffer_flush();
return 0; return 0;
} }
...@@ -35,6 +35,13 @@ int yyerror (char *s); ...@@ -35,6 +35,13 @@ int yyerror (char *s);
/* Function used to tokenize string representing function (this function /* Function used to tokenize string representing function (this function
is generated by scanner generator). */ is generated by scanner generator). */
int yylex (void); 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. */ /* Parser semantic values type. */
...@@ -63,7 +70,6 @@ int yylex (void); ...@@ -63,7 +70,6 @@ int yylex (void);
input input
: expression '\n' { : expression '\n' {
matheval_root = $1; matheval_root = $1;
yyerrok;
return 1; return 1;
} }
; ;
...@@ -115,5 +121,6 @@ int yyerror(char* s) ...@@ -115,5 +121,6 @@ int yyerror(char* s)
/* Indicate parsing error through appropriate flag and stop /* Indicate parsing error through appropriate flag and stop
parsing. */ parsing. */
matheval_ok = 0; matheval_ok = 0;
force_buffer_flush();
return 0; return 0;
} }
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
/* A lexical scanner generated by flex */ /* A lexical scanner generated by flex */
/* Scanner skeleton version: /* 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 #define FLEX_SCANNER
...@@ -1704,3 +1704,5 @@ 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; return count;
} }
int force_buffer_flush() { YY_FLUSH_BUFFER; }
...@@ -124,3 +124,5 @@ 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; return count;
} }
int force_buffer_flush() { YY_FLUSH_BUFFER; }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment