77 * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
10+ * src/bin/pgbench/exprparse.y
11+ *
1012 *-------------------------------------------------------------------------
1113 */
1214
@@ -19,16 +21,19 @@ PgBenchExpr *expr_parse_result;
1921static PgBenchExprList *make_elist (PgBenchExpr *exp, PgBenchExprList *list);
2022static PgBenchExpr *make_integer_constant (int64 ival);
2123static PgBenchExpr *make_variable (char *varname);
22- static PgBenchExpr *make_op (const char *operator , PgBenchExpr *lexpr ,
23- PgBenchExpr *rexpr);
24- static int find_func (const char *fname);
25- static PgBenchExpr *make_func (const int fnumber, PgBenchExprList *args);
24+ static PgBenchExpr *make_op (yyscan_t yyscanner, const char *operator ,
25+ PgBenchExpr *lexpr, PgBenchExpr *rexpr);
26+ static int find_func (yyscan_t yyscanner, const char *fname);
27+ static PgBenchExpr *make_func (yyscan_t yyscanner, int fnumber, PgBenchExprList *args);
2628
2729%}
2830
2931%expect 0
3032%name-prefix =" expr_yy"
3133
34+ %parse-param {yyscan_t yyscanner}
35+ %lex-param {yyscan_t yyscanner}
36+
3237%union
3338{
3439 int64 ival;
@@ -43,7 +48,6 @@ static PgBenchExpr *make_func(const int fnumber, PgBenchExprList *args);
4348%type <str> VARIABLE FUNCTION
4449
4550%token INTEGER VARIABLE FUNCTION
46- %token CHAR_ERROR /* never used, will raise a syntax error */
4751
4852/* Precedence: lowest to highest */
4953%left ' +' ' -'
@@ -61,18 +65,19 @@ elist: { $$ = NULL; }
6165
6266expr : ' (' expr ' )' { $$ = $2 ; }
6367 | ' +' expr %prec UMINUS { $$ = $2 ; }
64- | ' -' expr %prec UMINUS { $$ = make_op(" -" , make_integer_constant(0 ), $2 ); }
65- | expr ' +' expr { $$ = make_op(" +" , $1 , $3 ); }
66- | expr ' -' expr { $$ = make_op(" -" , $1 , $3 ); }
67- | expr ' *' expr { $$ = make_op(" *" , $1 , $3 ); }
68- | expr ' /' expr { $$ = make_op(" /" , $1 , $3 ); }
69- | expr ' %' expr { $$ = make_op(" %" , $1 , $3 ); }
68+ | ' -' expr %prec UMINUS { $$ = make_op(yyscanner, " -" ,
69+ make_integer_constant (0 ), $2); }
70+ | expr ' +' expr { $$ = make_op(yyscanner, " +" , $1 , $3 ); }
71+ | expr ' -' expr { $$ = make_op(yyscanner, " -" , $1 , $3 ); }
72+ | expr ' *' expr { $$ = make_op(yyscanner, " *" , $1 , $3 ); }
73+ | expr ' /' expr { $$ = make_op(yyscanner, " /" , $1 , $3 ); }
74+ | expr ' %' expr { $$ = make_op(yyscanner, " %" , $1 , $3 ); }
7075 | INTEGER { $$ = make_integer_constant($1 ); }
7176 | VARIABLE { $$ = make_variable($1 ); }
72- | function ' (' elist ' )' { $$ = make_func($1 , $3 ); }
77+ | function ' (' elist ' )' { $$ = make_func(yyscanner, $1 , $3 ); }
7378 ;
7479
75- function : FUNCTION { $$ = find_func($1 ); pg_free($1 ); }
80+ function : FUNCTION { $$ = find_func(yyscanner, $1 ); pg_free($1 ); }
7681 ;
7782
7883%%
@@ -98,9 +103,10 @@ make_variable(char *varname)
98103}
99104
100105static PgBenchExpr *
101- make_op (const char *operator , PgBenchExpr *lexpr, PgBenchExpr *rexpr)
106+ make_op (yyscan_t yyscanner, const char *operator ,
107+ PgBenchExpr *lexpr, PgBenchExpr *rexpr)
102108{
103- return make_func (find_func (operator ),
109+ return make_func (yyscanner, find_func (yyscanner, operator ),
104110 make_elist (rexpr, make_elist (lexpr, NULL )));
105111}
106112
@@ -139,7 +145,7 @@ static struct
139145 * or fail if the function is unknown.
140146 */
141147static int
142- find_func (const char * fname)
148+ find_func (yyscan_t yyscanner, const char *fname)
143149{
144150 int i = 0 ;
145151
@@ -150,7 +156,7 @@ find_func(const char * fname)
150156 i++;
151157 }
152158
153- expr_yyerror_more (" unexpected function name" , fname);
159+ expr_yyerror_more (yyscanner, " unexpected function name" , fname);
154160
155161 /* not reached */
156162 return -1 ;
@@ -198,21 +204,21 @@ elist_length(PgBenchExprList *list)
198204
199205/* Build function call expression */
200206static PgBenchExpr *
201- make_func (const int fnumber, PgBenchExprList *args)
207+ make_func (yyscan_t yyscanner, int fnumber, PgBenchExprList *args)
202208{
203209 PgBenchExpr *expr = pg_malloc (sizeof (PgBenchExpr));
204210
205211 Assert (fnumber >= 0 );
206212
207213 if (PGBENCH_FUNCTIONS[fnumber].nargs >= 0 &&
208214 PGBENCH_FUNCTIONS[fnumber].nargs != elist_length (args))
209- expr_yyerror_more (" unexpected number of arguments" ,
215+ expr_yyerror_more (yyscanner, " unexpected number of arguments" ,
210216 PGBENCH_FUNCTIONS[fnumber].fname );
211217
212218 /* check at least one arg for min & max */
213219 if (PGBENCH_FUNCTIONS[fnumber].nargs == -1 &&
214220 elist_length (args) == 0 )
215- expr_yyerror_more (" at least one argument expected" ,
221+ expr_yyerror_more (yyscanner, " at least one argument expected" ,
216222 PGBENCH_FUNCTIONS[fnumber].fname );
217223
218224 expr->etype = ENODE_FUNCTION;
@@ -226,4 +232,15 @@ make_func(const int fnumber, PgBenchExprList *args)
226232 return expr;
227233}
228234
235+ /*
236+ * exprscan.l is compiled as part of exprparse.y. Currently, this is
237+ * unavoidable because exprparse does not create a .h file to export
238+ * its token symbols. If these files ever grow large enough to be
239+ * worth compiling separately, that could be fixed; but for now it
240+ * seems like useless complication.
241+ */
242+
243+ /* First, get rid of "#define yyscan_t" from pgbench.h */
244+ #undef yyscan_t
245+
229246#include " exprscan.c"
0 commit comments