added a prefix for the tokens

This commit is contained in:
Pedro 2014-10-22 16:30:45 +02:00
parent d2baa4a3c0
commit e71b76dc71
3 changed files with 13 additions and 13 deletions

View File

@ -54,7 +54,7 @@ typedef void* yyscan_t;
%parse-param { Statement **statement } %parse-param { Statement **statement }
%parse-param { yyscan_t scanner } %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) ** Define all data-types (http://www.gnu.org/software/bison/manual/html_node/Union-Decl.html)
@ -182,12 +182,12 @@ predicate:
comparison_predicate: comparison_predicate:
scalar_exp EQUALS scalar_exp { $$ = makePredicate($1, EQUALS, $3); } scalar_exp EQUALS scalar_exp { $$ = makePredicate($1, SQL_EQUALS, $3); }
| scalar_exp NOTEQUALS scalar_exp { $$ = makePredicate($1, NOTEQUALS, $3); } | scalar_exp NOTEQUALS scalar_exp { $$ = makePredicate($1, SQL_NOTEQUALS, $3); }
| scalar_exp LESS scalar_exp { $$ = makePredicate($1, LESS, $3); } | scalar_exp LESS scalar_exp { $$ = makePredicate($1, SQL_LESS, $3); }
| scalar_exp GREATER scalar_exp { $$ = makePredicate($1, GREATER, $3); } | scalar_exp GREATER scalar_exp { $$ = makePredicate($1, SQL_GREATER, $3); }
| scalar_exp LESSEQ scalar_exp { $$ = makePredicate($1, LESSEQ, $3); } | scalar_exp LESSEQ scalar_exp { $$ = makePredicate($1, SQL_LESSEQ, $3); }
| scalar_exp GREATEREQ scalar_exp { $$ = makePredicate($1, GREATEREQ, $3); } | scalar_exp GREATEREQ scalar_exp { $$ = makePredicate($1, SQL_GREATEREQ, $3); }
; ;
// TODO: Expression can also be scalar_exp // TODO: Expression can also be scalar_exp

View File

@ -15,7 +15,7 @@
#include "bison_parser.h" #include "bison_parser.h"
#include <stdio.h> #include <stdio.h>
#define TOKEN(name) { return name; } #define TOKEN(name) { return SQL_##name; }
%} %}
/*************************** /***************************
@ -63,26 +63,26 @@ OR TOKEN(OR)
">=" TOKEN(GREATEREQ) ">=" TOKEN(GREATEREQ)
[-+*/(),.;] TOKEN(yytext[0]) [-+*/(),.;] { return yytext[0]; }
[0-9]+ | [0-9]+ |
[0-9]+"."[0-9]* | [0-9]+"."[0-9]* |
"."[0-9]* { "."[0-9]* {
yylval->number = atof(yytext); yylval->number = atof(yytext);
return FLOAT; return SQL_FLOAT;
} }
[A-Za-z][A-Za-z0-9_]* { [A-Za-z][A-Za-z0-9_]* {
yylval->sval = strdup(yytext); yylval->sval = strdup(yytext);
return NAME; return SQL_NAME;
} }
'[^'\n]*' { '[^'\n]*' {
yylval->sval = strdup(yytext); yylval->sval = strdup(yytext);
return STRING; return SQL_STRING;
} }

View File

@ -38,7 +38,7 @@ void SelectTest1() {
ASSERT(stmt->where_clause != NULL); ASSERT(stmt->where_clause != NULL);
ASSERT(stmt->where_clause->expr->type == eExprColumnRef); ASSERT(stmt->where_clause->expr->type == eExprColumnRef);
ASSERT_STR(stmt->where_clause->expr->name, "age"); 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->type == eExprLiteralFloat);
ASSERT(stmt->where_clause->expr2->float_literal == 12.5); ASSERT(stmt->where_clause->expr2->float_literal == 12.5);