8 ParsedData *parsedData;
11 void yyerror(const char* Msg);
21 %token <stringval> STRING FIELD NUMBER_STRING BINARY_STRING DOUBLE OPERATOR PARAMETER
22 %token <stringval> SELECT FROM WHERE BETWEEN AND OR NOT
23 %token <stringval> STAR
24 %token <stringval> INSERT INTO VALUES
25 %token <stringval> DELETE UPDATE SET NULL_VALUE
26 %token <stringval> CREATE TABLE PRIMARY KEY DEFAULT INDEX ON HASH TREE UNIQUE DROP
27 %token <stringval> INT_TYPE LONG_TYPE SHORT_TYPE DOUBLE_TYPE TIMESTAMP_TYPE DATE_TYPE CHAR_TYPE TIME_TYPE
28 %token ';' ',' '(' ')'
29 %type <stringval> ident field value
30 %type <predicate> conditions condition
33 command: select_statement { YYACCEPT; }
34 | insert_statement { YYACCEPT; }
35 | delete_statement { YYACCEPT; }
36 | update_statement { YYACCEPT; }
37 | ddl_statement { YYACCEPT; }
40 select_statement: SELECT field_list FROM ident where_clause_opt semicolon_opt
42 parsedData->setStmtType(SelectStatement);
43 parsedData->setTableName($4);
48 field_list: field_list field_list_L
51 field_list_L: ',' field
54 insert_statement: INSERT INTO ident field_list_opt VALUES '(' value_list ')' semicolon_opt
56 parsedData->setStmtType(InsertStatement);
57 parsedData->setTableName($3);
66 value_list: value_list value_list_L
69 parsedData->insertValue((char*)$1);
73 value_list_L: ',' value
75 parsedData->insertValue((char*)$2);
80 delete_statement: DELETE FROM ident where_clause_opt semicolon_opt
82 parsedData->setStmtType(DeleteStatement);
83 parsedData->setTableName($3);
88 update_statement: UPDATE ident SET assign_list where_clause_opt semicolon_opt
90 parsedData->setStmtType(UpdateStatement);
91 parsedData->setTableName($2);
100 assign_list: assign_list assign_list_L
104 assign_list_L: ',' assign_stmt
106 assign_stmt: ident OPERATOR value
108 parsedData->insertUpdateValue( (char*) $1, (char*) $3);
109 free( $1 ); free( $3 );
113 where_clause_opt: WHERE conditions
117 conditions: condition AND condition
120 pred = parsedData->insertPredicate((Predicate*) $1, OpAnd, (Predicate*) $3);
121 parsedData->setCondition((Predicate*)pred);
125 | condition OR condition
128 pred = parsedData->insertPredicate((Predicate*) $1, OpOr, (Predicate*) $3);
129 parsedData->setCondition((Predicate*)pred);
135 pred = parsedData->insertPredicate((Predicate*) $2, OpNot, NULL);
136 parsedData->setCondition((Predicate*)pred);
137 //((Predicate*)$2)->print();
142 parsedData->setCondition((Predicate*)$1);
143 //((Predicate*)$1)->print();
147 condition: ident OPERATOR value
149 ComparisionOp op = AllDataType::getComparisionOperator((char*)$2);
151 void **ptr = parsedData->insertCondValueAndGetPtr((char*)$1, (char*)$3);
152 pred = parsedData->insertPredicate((char*) $1, op, ptr);
153 free( $1 ); free( $3 );
156 | ident BETWEEN value AND value
158 void **ptr1 = parsedData->insertCondValueAndGetPtr((char*)$1, (char*)$3);
159 void **ptr2 = parsedData->insertCondValueAndGetPtr((char*)$1, (char*)$5);
160 Predicate *pred1, *pred2, *pred3;
161 pred1 = parsedData->insertPredicate((char*) $1, OpGreaterThanEquals, ptr1);
162 pred2 = parsedData->insertPredicate((char*) $1, OpLessThanEquals, ptr2);
163 pred3 = parsedData->insertPredicate(pred1, OpAnd, pred2);
164 free( $1 ); free( $3 ); free( $5 );
170 parsedData->insertField((char*)$1);
175 parsedData->insertField((char*)$1);
179 ident: FIELD { $$ = $1; }
181 value: STRING { $$ = $1; }
182 | NUMBER_STRING { $$ = $1; }
183 | BINARY_STRING { $$ = $1; }
184 | DOUBLE { $$ = $1; }
185 | PARAMETER { $$ = $1; }
186 | NULL_VALUE { $$ = (char*) 0; }
189 ddl_statement: CREATE TABLE ident '(' create_defn_list ')' semicolon_opt
191 parsedData->setStmtType(CreateTableStatement);
192 parsedData->setTableName($3);
195 | CREATE INDEX ident ON ident '(' field_list ')' opt_constr_type opt_ind_type semicolon_opt
197 parsedData->setStmtType(CreateIndexStatement);
198 parsedData->setIndexName($3);
199 parsedData->setTableName($5);
205 parsedData->setStmtType(DropTableStatement);
206 parsedData->setTableName($3);
211 parsedData->setStmtType(DropIndexStatement);
212 parsedData->setIndexName($3);
219 parsedData->setIndexType(hashIndex);
223 parsedData->setIndexType(treeIndex);
227 parsedData->setIndexType(hashIndex);
232 parsedData->setUnique(true);
236 parsedData->setUnique(true);
237 parsedData->setPrimary(true);
241 parsedData->setUnique(false);
242 parsedData->setPrimary(false);
245 create_defn_list: create_defn_list create_defn_list_L
249 create_defn_list_L: ',' create_defn
252 create_defn: field_defn
254 parsedData->insertFldDef();
259 field_defn: field_name field_type size_opt null_expr_opt default_expr_opt
264 parsedData->setFldName($1);
268 | '(' NUMBER_STRING ')'
270 parsedData->setFldLength(atoi($2));
282 parsedData->setFldNotNull(true);
285 constraint_defn: primary_key_constraint
288 primary_key_constraint: PRIMARY KEY '(' field_list ')'
293 parsedData->setFldType(typeInt);
297 parsedData->setFldType(typeLong);
301 parsedData->setFldType(typeShort);
305 parsedData->setFldType(typeLongLong);
309 parsedData->setFldType(typeFloat);
313 parsedData->setFldType(typeDouble);
318 parsedData->setFldType(typeDate);
323 parsedData->setFldType(typeTime);
328 parsedData->setFldType(typeTimeStamp);
333 parsedData->setFldType(typeString);
339 void yyerror(const char* Msg) {
341 fprintf(stderr, "[Parser: %s] %s\n", Msg, yytext);