|
@@ -30,7 +30,7 @@ cJSON* jroot;
|
|
%token IDENTIFIER
|
|
%token IDENTIFIER
|
|
|
|
|
|
%token SELECT FROM WHERE INSERT INTO VALUES DELETE UPDATE SET JOIN CREATE TABLE
|
|
%token SELECT FROM WHERE INSERT INTO VALUES DELETE UPDATE SET JOIN CREATE TABLE
|
|
-%token AND OR NOT IN
|
|
|
|
|
|
+%token AND OR NOT
|
|
%token INT_V FLOAT_V STRING_V // 作为 value 出现的
|
|
%token INT_V FLOAT_V STRING_V // 作为 value 出现的
|
|
%token INT_T FLOAT_T STRING_T // 作为 字面量 type 出现的情况
|
|
%token INT_T FLOAT_T STRING_T // 作为 字面量 type 出现的情况
|
|
|
|
|
|
@@ -42,7 +42,7 @@ cJSON* jroot;
|
|
%type <iv> INT_V
|
|
%type <iv> INT_V
|
|
%type <fv> FLOAT_V
|
|
%type <fv> FLOAT_V
|
|
%type <sv> STRING_V
|
|
%type <sv> STRING_V
|
|
-%type <sv> IDENTIFIER data_type PRIMARY_KEY col_options bin_compare_op
|
|
|
|
|
|
+%type <sv> IDENTIFIER data_type PRIMARY_KEY col_options bin_compare_op bin_logical_op
|
|
%type <jv> create_definition create_col_list create_table_stmt data_value
|
|
%type <jv> create_definition create_col_list create_table_stmt data_value
|
|
%type <jv> insert_stmt insert_list
|
|
%type <jv> insert_stmt insert_list
|
|
%type <jv> update_stmt update_list single_assign_item
|
|
%type <jv> update_stmt update_list single_assign_item
|
|
@@ -198,14 +198,16 @@ single_assign_item: identifier '=' identifier_or_const_value {
|
|
}
|
|
}
|
|
;
|
|
;
|
|
where_conditions: where_condition_item {
|
|
where_conditions: where_condition_item {
|
|
- cJSON* node = cJSON_CreateArray();
|
|
|
|
- cJSON_AddItemToArray(node, $1);
|
|
|
|
- $$=node;
|
|
|
|
- }
|
|
|
|
- | where_conditions AND where_condition_item {
|
|
|
|
- cJSON_AddItemToArray($1, $3);
|
|
|
|
$$=$1;
|
|
$$=$1;
|
|
}
|
|
}
|
|
|
|
+ | where_conditions bin_logical_op where_condition_item {
|
|
|
|
+ cJSON* node = cJSON_CreateObject();
|
|
|
|
+ cJSON_AddStringToObject(node, "type", $2);
|
|
|
|
+
|
|
|
|
+ cJSON_AddItemToObject(node, "left", $1);
|
|
|
|
+ cJSON_AddItemToObject(node, "right", $3);
|
|
|
|
+ $$=node;
|
|
|
|
+ }
|
|
;
|
|
;
|
|
|
|
|
|
identifier: IDENTIFIER {
|
|
identifier: IDENTIFIER {
|
|
@@ -219,19 +221,21 @@ identifier_or_const_value: identifier {$$=$1;}
|
|
|
|
|
|
where_condition_item: identifier_or_const_value bin_compare_op identifier_or_const_value {
|
|
where_condition_item: identifier_or_const_value bin_compare_op identifier_or_const_value {
|
|
cJSON* node = cJSON_CreateObject();
|
|
cJSON* node = cJSON_CreateObject();
|
|
- cJSON_AddStringToObject(node, "type", "where_condition");
|
|
|
|
|
|
+ cJSON_AddStringToObject(node, "type", $2);
|
|
cJSON_AddItemToObject(node, "left", $1);
|
|
cJSON_AddItemToObject(node, "left", $1);
|
|
cJSON_AddItemToObject(node, "right", $3);
|
|
cJSON_AddItemToObject(node, "right", $3);
|
|
$$=node;
|
|
$$=node;
|
|
};
|
|
};
|
|
|
|
|
|
-bin_compare_op: '=' {$$ = "=";}
|
|
|
|
- | '>' {$$ = ">";}
|
|
|
|
- | '<' {$$ = "<";}
|
|
|
|
- | ">=" {$$ = ">=";}
|
|
|
|
- | "<=" {$$ = "<=";}
|
|
|
|
- | "!=" {$$ = "!=";}
|
|
|
|
|
|
+bin_compare_op: '=' {$$ = "相等";}
|
|
|
|
+ | '>' {$$ = "大于";}
|
|
|
|
+ | '<' {$$ = "小于";}
|
|
|
|
+ | ">=" {$$ = "大等";}
|
|
|
|
+ | "<=" {$$ = "小等";}
|
|
|
|
+ | "!=" {$$ = "不等";}
|
|
;
|
|
;
|
|
|
|
+bin_logical_op: AND {$$ = "且";}
|
|
|
|
+ | OR {$$ = "或";}
|
|
|
|
|
|
delete_stmt: DELETE FROM IDENTIFIER WHERE where_conditions NEWLINE {
|
|
delete_stmt: DELETE FROM IDENTIFIER WHERE where_conditions NEWLINE {
|
|
cJSON* node = cJSON_CreateObject();
|
|
cJSON* node = cJSON_CreateObject();
|