Procházet zdrojové kódy

多逻辑操作符合并

myuan před 2 roky
rodič
revize
d11355e65d
2 změnil soubory, kde provedl 21 přidání a 15 odebrání
  1. 2 0
      src/calc.l
  2. 19 15
      src/calc.y

+ 2 - 0
src/calc.l

@@ -40,6 +40,8 @@ extern YYSTYPE yylval;
 "FLOAT"     {cp_yylval_and_return(FLOAT_T);}
 "STRING"    {cp_yylval_and_return(STRING_T);}
 "AND"       return AND;
+"OR"        return OR;
+"NOT"       return NOT;
 
 
 ;		    {return NEWLINE;}

+ 19 - 15
src/calc.y

@@ -30,7 +30,7 @@ cJSON* jroot;
 %token IDENTIFIER 
 
 %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_T FLOAT_T STRING_T // 作为 字面量 type 出现的情况
 
@@ -42,7 +42,7 @@ cJSON* jroot;
 %type <iv> INT_V
 %type <fv> FLOAT_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> insert_stmt insert_list 
 %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 {
-		cJSON* node = cJSON_CreateArray();
-		cJSON_AddItemToArray(node, $1);
-		$$=node;
-	}
-	|  where_conditions AND where_condition_item {
-		cJSON_AddItemToArray($1, $3);
 		$$=$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 {
@@ -219,19 +221,21 @@ identifier_or_const_value: identifier {$$=$1;}
 
 where_condition_item: identifier_or_const_value bin_compare_op identifier_or_const_value {
 		cJSON* node = cJSON_CreateObject();
-		cJSON_AddStringToObject(node, "type", "where_condition");
+		cJSON_AddStringToObject(node, "type", $2);
 		cJSON_AddItemToObject(node, "left", $1);
 		cJSON_AddItemToObject(node, "right", $3);
 		$$=node;
 	};
 
-bin_compare_op: '=' {$$ = "=";}
-	| '>' {$$ = ">";}
-	| '<' {$$ = "<";}
-	| ">=" {$$ = ">=";}
-	| "<=" {$$ = "<=";}
-	| "!=" {$$ = "!=";}
+bin_compare_op: '=' {$$ = "相等";}
+	| '>' {$$ = "大于";}
+	| '<' {$$ = "小于";}
+	| ">=" {$$ = "大等";}
+	| "<=" {$$ = "小等";}
+	| "!=" {$$ = "不等";}
 ;
+bin_logical_op: AND {$$ = "且";}
+	| OR {$$ = "或";}
 
 delete_stmt: DELETE FROM IDENTIFIER WHERE where_conditions NEWLINE {
 		cJSON* node = cJSON_CreateObject();