The point of this change is to use %pure-parser in pgbench's exprparse.y.
The immediate reason is that it turns out very ancient versions of bison
have a bug with the combination of a reentrant lexer and non-reentrant
parser. We could consider dropping support for such ancient bisons; but
considering that we might well need exprparse.y to be reentrant some day,
it seems better to make it so right now than to move the portability
goalposts. (AFAICT there's no particular performance consequence to this
change, either, so there's no good reason not to do it.)
Now, %pure-parser assumes that the called lexer is built with %option
bison-bridge. Because we're assuming bitwise compatibility of yyscan_t
(yyguts_t) data structures among all the psql/pgbench lexers, that
requirement propagates back to psql's lexers as well. But it's just a
few lines of change on that side too; and if psqlscan.l is to set the
baseline for a possibly-large family of lexers, it should err on the
side of including not omitting useful features.
%}
+%pure-parser
%expect 0
%name-prefix="expr_yy"
/* First, get rid of "#define yyscan_t" from pgbench.h */
#undef yyscan_t
+/* ... and the yylval macro, which flex will have its own definition for */
+#undef yylval
#include "exprscan.c"
/* Except for the prefix, these options should match psqlscan.l */
%option reentrant
+%option bison-bridge
%option 8bit
%option never-interactive
%option nodefault
"," { return ','; }
:{alnum}+ {
- yylval.str = pg_strdup(yytext + 1);
+ yylval->str = pg_strdup(yytext + 1);
return VARIABLE;
}
{digit}+ {
- yylval.ival = strtoint64(yytext);
+ yylval->ival = strtoint64(yytext);
return INTEGER;
}
{alpha}{alnum}* {
- yylval.str = pg_strdup(yytext);
+ yylval->str = pg_strdup(yytext);
return FUNCTION;
}
{
PsqlScanState state = yyget_extra(yyscanner);
int error_detection_offset = expr_scanner_offset(state) - 1;
+ YYSTYPE lval;
char *full_line;
size_t l;
*/
if (!last_was_newline)
{
- while (yylex(yyscanner))
+ while (yylex(&lval, yyscanner))
/* skip */ ;
}
expr_lex_one_word(PsqlScanState state, PQExpBuffer word_buf, int *offset)
{
int lexresult;
+ YYSTYPE lval;
/* Must be scanning already */
Assert(state->scanbufhandle != NULL);
state->start_state = INITIAL;
/* And lex. */
- lexresult = yylex(state->scanner);
+ lexresult = yylex(&lval, state->scanner);
/*
* Save start offset of word, if any. We could do this more efficiently,
* This file is included outside exprscan.l, in places where we can't see
* flex's definition of typedef yyscan_t. Fortunately, it's documented as
* being "void *", so we can use a macro to keep the function declarations
- * here looking like the definitions in exprscan.l. exprparse.y also
- * uses this to be able to declare things as "yyscan_t".
+ * here looking like the definitions in exprscan.l. exprparse.y and
+ * pgbench.c also use this to be able to declare things as "yyscan_t".
*/
#define yyscan_t void *
+/*
+ * Likewise, we can't see exprparse.y's definition of union YYSTYPE here,
+ * but for now there's no need to know what the union contents are.
+ */
+union YYSTYPE;
+
/* Types of expression nodes */
typedef enum PgBenchExprType
{
extern PgBenchExpr *expr_parse_result;
extern int expr_yyparse(yyscan_t yyscanner);
-extern int expr_yylex(yyscan_t yyscanner);
+extern int expr_yylex(union YYSTYPE *lvalp, yyscan_t yyscanner);
extern void expr_yyerror(yyscan_t yyscanner, const char *str) pg_attribute_noreturn();
extern void expr_yyerror_more(yyscan_t yyscanner, const char *str,
const char *more) pg_attribute_noreturn();
%{
#include "psqlscan_int.h"
+/*
+ * We must have a typedef YYSTYPE for yylex's first argument, but this lexer
+ * doesn't presently make use of that argument, so just declare it as int.
+ */
+typedef int YYSTYPE;
+
/*
* Set the type of yyextra; we use it as a pointer back to the containing
* PsqlScanState.
%}
%option reentrant
+%option bison-bridge
%option 8bit
%option never-interactive
%option nodefault
yy_switch_to_buffer(state->scanbufhandle, state->scanner);
/* And lex. */
- lexresult = yylex(state->scanner);
+ lexresult = yylex(NULL, state->scanner);
/*
* Check termination state and return appropriate result info.
%{
#include "psqlscan_int.h"
+/*
+ * We must have a typedef YYSTYPE for yylex's first argument, but this lexer
+ * doesn't presently make use of that argument, so just declare it as int.
+ */
+typedef int YYSTYPE;
+
/*
* Set the type of yyextra; we use it as a pointer back to the containing
* PsqlScanState.
%}
+/* Except for the prefix, these options should match psqlscan.l */
%option reentrant
+%option bison-bridge
%option 8bit
%option never-interactive
%option nodefault
state->start_state = xslashcmd;
/* And lex. */
- yylex(state->scanner);
+ yylex(NULL, state->scanner);
/* There are no possible errors in this lex state... */
state->start_state = xslashargstart;
/* And lex. */
- lexresult = yylex(state->scanner);
+ lexresult = yylex(NULL, state->scanner);
/* Save final state for a moment... */
final_state = state->start_state;
state->start_state = xslashend;
/* And lex. */
- yylex(state->scanner);
+ yylex(NULL, state->scanner);
/* There are no possible errors in this lex state... */