|
@@ -76,16 +76,16 @@ cJSON* jroot;
|
|
%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
|
|
-%type <jv> where_condition_item identifier identifier_or_const_value the_whole_where_smt
|
|
|
|
|
|
+%type <jv> where_condition_item identifier identifier_or_const_value
|
|
%type <jv> delete_stmt select_stmt select_item select_items
|
|
%type <jv> delete_stmt select_stmt select_item select_items
|
|
%type <jv> data_value_list identifier_or_const_value_or_const_value_list
|
|
%type <jv> data_value_list identifier_or_const_value_or_const_value_list
|
|
-%type <jv> search_expr compare_expr single_expr expr where_expr logical_expr negative_expr op_where_expr expr_list
|
|
|
|
|
|
+%type <jv> search_expr compare_expr single_expr expr where_expr logical_expr negative_expr op_where_expr expr_list contains_expr
|
|
|
|
|
|
|
|
|
|
-// %left OR
|
|
|
|
-// %left AND
|
|
|
|
-// %right NOT
|
|
|
|
-// %nonassoc '=' '>' '<'
|
|
|
|
|
|
+%left OR
|
|
|
|
+%left AND
|
|
|
|
+%right NOT
|
|
|
|
+%nonassoc '=' '>' '<'
|
|
// %left '+' '-'
|
|
// %left '+' '-'
|
|
// %left '*' '/'
|
|
// %left '*' '/'
|
|
|
|
|
|
@@ -224,12 +224,6 @@ single_assign_item: identifier '=' identifier_or_const_value {
|
|
}
|
|
}
|
|
;
|
|
;
|
|
|
|
|
|
-the_whole_where_smt: {$$=cJSON_CreateObject();}
|
|
|
|
- | WHERE where_expr {$$=$2;}
|
|
|
|
-;
|
|
|
|
-
|
|
|
|
-// where 后的条件跟 select 中的有本质区别
|
|
|
|
-// select 中的只是常量或者字段名, 而 where 中的是表达式
|
|
|
|
|
|
|
|
single_expr: identifier {$$=$1;}
|
|
single_expr: identifier {$$=$1;}
|
|
| IDENTIFIER '.' IDENTIFIER {
|
|
| IDENTIFIER '.' IDENTIFIER {
|
|
@@ -246,7 +240,6 @@ where_expr: logical_expr {
|
|
MEET_JSON(logical_expr from where_expr, $1);
|
|
MEET_JSON(logical_expr from where_expr, $1);
|
|
$$=$1;
|
|
$$=$1;
|
|
}
|
|
}
|
|
- | '(' where_expr ')' {$$=$2;}
|
|
|
|
;
|
|
;
|
|
op_where_expr: {$$=cJSON_CreateObject();}
|
|
op_where_expr: {$$=cJSON_CreateObject();}
|
|
| WHERE where_expr {$$=$2;}
|
|
| WHERE where_expr {$$=$2;}
|
|
@@ -255,21 +248,32 @@ compare_expr: compare_expr bin_cmp_op compare_expr {
|
|
fprintf(stderr, "compare_expr %s\n", $2);
|
|
fprintf(stderr, "compare_expr %s\n", $2);
|
|
SIMPLE_OP_NODE($$, $2, $1, $3);}
|
|
SIMPLE_OP_NODE($$, $2, $1, $3);}
|
|
| single_expr {MEET_JSON(single_expr from compare_expr, $1); $$=$1;}
|
|
| single_expr {MEET_JSON(single_expr from compare_expr, $1); $$=$1;}
|
|
- | where_expr {MEET_JSON(where_expr from compare_expr, $1) $$=$1;}
|
|
|
|
|
|
+ | '(' where_expr ')' {MEET(括号where_expr from compare_expr); $$=$2;}
|
|
|
|
|
|
;
|
|
;
|
|
negative_expr: NOT negative_expr {
|
|
negative_expr: NOT negative_expr {
|
|
fprintf(stderr, "negative_expr\n");
|
|
fprintf(stderr, "negative_expr\n");
|
|
SIMPLE_OP_NODE_ONLY_LEFT($$, "非", $2);}
|
|
SIMPLE_OP_NODE_ONLY_LEFT($$, "非", $2);}
|
|
| compare_expr {MEET_JSON(compare_expr from negative_expr, $1) $$=$1;}
|
|
| compare_expr {MEET_JSON(compare_expr from negative_expr, $1) $$=$1;}
|
|
- | where_expr {MEET(where_expr from negative_expr) $$=$1;}
|
|
|
|
|
|
+ | '(' negative_expr ')' {MEET_JSON(negative_expr from negative_expr, $2) $$=$2;}
|
|
;
|
|
;
|
|
-logical_expr: logical_expr bin_logical_op negative_expr {
|
|
|
|
|
|
+contains_expr: contains_expr bin_contains_op '(' select_stmt ')' {
|
|
|
|
+ MEET_JSON(logical_expr bin_contains_op select_stmt, $2);
|
|
|
|
+ SIMPLE_OP_NODE($$, $2, $1, $4)
|
|
|
|
+ }
|
|
|
|
+ | contains_expr bin_contains_op '(' expr_list ')' {
|
|
|
|
+ MEET_VAR(logical_expr bin_contains_op expr_list, $2);
|
|
|
|
+ SIMPLE_OP_NODE($$, $2, $1, $4)
|
|
|
|
+ }
|
|
|
|
+ | negative_expr {MEET_JSON(negative_expr from contains_expr, $1); $$=$1;}
|
|
|
|
+
|
|
|
|
+logical_expr: logical_expr bin_logical_op contains_expr {
|
|
fprintf(stderr, "logical_expr %s\n", $2);
|
|
fprintf(stderr, "logical_expr %s\n", $2);
|
|
SIMPLE_OP_NODE($$, $2, $1, $3);}
|
|
SIMPLE_OP_NODE($$, $2, $1, $3);}
|
|
- | negative_expr {MEET_JSON(negative_expr from logical_expr, $1); $$=$1;}
|
|
|
|
|
|
+ | contains_expr {MEET_JSON(contains_expr from logical_expr, $1); $$=$1;}
|
|
| single_expr {MEET_JSON(single_expr from logical_expr, $1) $$=$1;}
|
|
| single_expr {MEET_JSON(single_expr from logical_expr, $1) $$=$1;}
|
|
- // | '(' logical_expr ')' {$$=$2;}
|
|
|
|
|
|
+ | negative_expr {MEET_JSON(negative_expr from logical_expr, $1); $$=$1;}
|
|
|
|
+
|
|
;
|
|
;
|
|
|
|
|
|
|
|
|
|
@@ -285,21 +289,11 @@ expr_list: {
|
|
cJSON_AddItemToArray(node, $1);
|
|
cJSON_AddItemToArray(node, $1);
|
|
$$=node;
|
|
$$=node;
|
|
}
|
|
}
|
|
- // | expr_list ',' logical_expr {
|
|
|
|
- // fprintf(stderr, "迭代 expr_list\n %s", cJSON_Print($1));
|
|
|
|
- // cJSON_AddItemToArray($1, $3);
|
|
|
|
- // $$=$1;
|
|
|
|
- // }
|
|
|
|
-;
|
|
|
|
-
|
|
|
|
-where_expr: logical_expr bin_contains_op '(' expr_list ')' {
|
|
|
|
- MEET_JSON(logical_expr bin_contains_op expr_list, $2);
|
|
|
|
- SIMPLE_OP_NODE($$, $2, $1, $4)
|
|
|
|
|
|
+ | expr_list ',' logical_expr {
|
|
|
|
+ fprintf(stderr, "迭代 expr_list\n %s", cJSON_Print($1));
|
|
|
|
+ cJSON_AddItemToArray($1, $3);
|
|
|
|
+ $$=$1;
|
|
}
|
|
}
|
|
- // | logical_expr bin_contains_op '(' select_stmt ')' {
|
|
|
|
- // MEET_JSON(logical_expr bin_contains_op select_stmt, $2);
|
|
|
|
- // SIMPLE_OP_NODE($$, $2, $1, $4)
|
|
|
|
- // }
|
|
|
|
;
|
|
;
|
|
|
|
|
|
identifier: IDENTIFIER {
|
|
identifier: IDENTIFIER {
|