From ff0167cde6133ed4163d9712f6f52ce176ecafb1 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 3 Nov 2014 23:26:33 +0100 Subject: [PATCH] added join definition to grammar. put limit and order tokens into lexer --- src/parser/bison_parser.y | 31 +++++++++++++++++++++++++------ src/parser/flex_lexer.l | 7 +++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/parser/bison_parser.y b/src/parser/bison_parser.y index 33b47f5..c118828 100644 --- a/src/parser/bison_parser.y +++ b/src/parser/bison_parser.y @@ -72,7 +72,9 @@ typedef void* yyscan_t; uint uval; hsql::Statement* statement; - hsql::SelectStatement* select_statement; + hsql::SelectStatement* select_stmt; + hsql::JoinStatement* join_stmt; + hsql::TableRef* table; hsql::Expr* expr; hsql::OrderDescription* order; @@ -102,7 +104,8 @@ typedef void* yyscan_t; ** Non-Terminal types (http://www.gnu.org/software/bison/manual/html_node/Type-Decl.html) *********************************/ %type statement -%type select_statement +%type select_statement +%type join_statement %type table_name %type from_clause table_ref table_ref_atomic %type expr scalar_expr unary_expr binary_expr function_expr star_expr @@ -153,17 +156,32 @@ input: // Atm: only select statements (future: insert, delete, etc...) statement: select_statement { $$ = $1; } - | /* empty */ { $$ = NULL; } + | join_statement { $$ = $1; } ; + + +/****************************** + ** Join Statements + ******************************/ + +join_statement: + select_statement JOIN table_ref ON join_condition + { + $$ = new JoinStatement(); + } + ; + +join_condition: + expr + ; + + /****************************** ** Select Statements ******************************/ -// TODO: join -// TODO: limit -// TODO: order by select_statement: SELECT select_list from_clause where_clause group_clause order_by_clause limit_clause { @@ -176,6 +194,7 @@ select_statement: s->limit = $7; $$ = s; } + | '(' select_statement ')' { $$ = $2; } ; diff --git a/src/parser/flex_lexer.l b/src/parser/flex_lexer.l index c82966f..012cfc6 100644 --- a/src/parser/flex_lexer.l +++ b/src/parser/flex_lexer.l @@ -58,6 +58,13 @@ NOT TOKEN(NOT) AND TOKEN(AND) OR TOKEN(OR) +LIMIT TOKEN(LIMIT) +ORDER TOKEN(ORDER) +ASC TOKEN(ASC) +DESC TOKEN(DESC) +JOIN TOKEN(JOIN) +ON TOKEN(ON) + "=" TOKEN(EQUALS) "<>" TOKEN(NOTEQUALS) "<" TOKEN(LESS)