From e71b76dc71a652ea0bb5f593f3c4421e51dfd27b Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 22 Oct 2014 16:30:45 +0200 Subject: [PATCH] added a prefix for the tokens --- src/bison/bison_parser.y | 14 +++++++------- src/bison/flex_lexer.l | 10 +++++----- src/sql_tests.cpp | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/bison/bison_parser.y b/src/bison/bison_parser.y index 2422b34..10ac20f 100644 --- a/src/bison/bison_parser.y +++ b/src/bison/bison_parser.y @@ -54,7 +54,7 @@ typedef void* yyscan_t; %parse-param { Statement **statement } %parse-param { yyscan_t scanner } - +%define api.token.prefix {SQL_} /********************************* ** Define all data-types (http://www.gnu.org/software/bison/manual/html_node/Union-Decl.html) @@ -182,12 +182,12 @@ predicate: comparison_predicate: - scalar_exp EQUALS scalar_exp { $$ = makePredicate($1, EQUALS, $3); } - | scalar_exp NOTEQUALS scalar_exp { $$ = makePredicate($1, NOTEQUALS, $3); } - | scalar_exp LESS scalar_exp { $$ = makePredicate($1, LESS, $3); } - | scalar_exp GREATER scalar_exp { $$ = makePredicate($1, GREATER, $3); } - | scalar_exp LESSEQ scalar_exp { $$ = makePredicate($1, LESSEQ, $3); } - | scalar_exp GREATEREQ scalar_exp { $$ = makePredicate($1, GREATEREQ, $3); } + scalar_exp EQUALS scalar_exp { $$ = makePredicate($1, SQL_EQUALS, $3); } + | scalar_exp NOTEQUALS scalar_exp { $$ = makePredicate($1, SQL_NOTEQUALS, $3); } + | scalar_exp LESS scalar_exp { $$ = makePredicate($1, SQL_LESS, $3); } + | scalar_exp GREATER scalar_exp { $$ = makePredicate($1, SQL_GREATER, $3); } + | scalar_exp LESSEQ scalar_exp { $$ = makePredicate($1, SQL_LESSEQ, $3); } + | scalar_exp GREATEREQ scalar_exp { $$ = makePredicate($1, SQL_GREATEREQ, $3); } ; // TODO: Expression can also be scalar_exp diff --git a/src/bison/flex_lexer.l b/src/bison/flex_lexer.l index 80bf361..3065e32 100644 --- a/src/bison/flex_lexer.l +++ b/src/bison/flex_lexer.l @@ -15,7 +15,7 @@ #include "bison_parser.h" #include -#define TOKEN(name) { return name; } +#define TOKEN(name) { return SQL_##name; } %} /*************************** @@ -63,26 +63,26 @@ OR TOKEN(OR) ">=" TOKEN(GREATEREQ) -[-+*/(),.;] TOKEN(yytext[0]) +[-+*/(),.;] { return yytext[0]; } [0-9]+ | [0-9]+"."[0-9]* | "."[0-9]* { yylval->number = atof(yytext); - return FLOAT; + return SQL_FLOAT; } [A-Za-z][A-Za-z0-9_]* { yylval->sval = strdup(yytext); - return NAME; + return SQL_NAME; } '[^'\n]*' { yylval->sval = strdup(yytext); - return STRING; + return SQL_STRING; } diff --git a/src/sql_tests.cpp b/src/sql_tests.cpp index f2ef14d..295ff3c 100644 --- a/src/sql_tests.cpp +++ b/src/sql_tests.cpp @@ -38,7 +38,7 @@ void SelectTest1() { ASSERT(stmt->where_clause != NULL); ASSERT(stmt->where_clause->expr->type == eExprColumnRef); ASSERT_STR(stmt->where_clause->expr->name, "age"); - ASSERT(stmt->where_clause->pred_type == LESS); + ASSERT(stmt->where_clause->pred_type == SQL_LESS); ASSERT(stmt->where_clause->expr2->type == eExprLiteralFloat); ASSERT(stmt->where_clause->expr2->float_literal == 12.5);