diff --git a/.gitignore b/.gitignore index 5fe5f8385256714fb2884bb45cf006ab359cb2b5..c49cd8d5931101f9a8738f48c8bb9e10bf04a051 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o +*.output .DS_Store SQLPParser.dSYM/ SQLPRefExp.dSYM/ diff --git a/SQLPGrammar.y b/SQLPGrammar.y index 641d6bd7fbf71fd89554b916dc1fb98b8da29768..24954219db2283134a6d5bfbfc42575efac4cdd8 100644 --- a/SQLPGrammar.y +++ b/SQLPGrammar.y @@ -135,45 +135,38 @@ UnionQuery ; SelectList - : Col + : SelectListElem ',' SelectList { - printf("SelectList 1\n"); - $$ = create_rename_operator($1, NULL); + printf("SelectListElem 1\n"); + $$ = create_select_list($1, $3); } - | Col AS AttrIdentifier + | SelectListElem { - printf("SelectList 2\n"); - $$ = create_as_operator($1, $3); + printf("SelectListElem 2\n"); + $$ = create_select_list($1, NULL); } - | Col ',' SelectList + ; + +SelectListElem + : Col { - printf("SelectList 3\n"); - $$ = create_rename_operator($1, $2); + printf("SelectListElem 1\n"); + $$ = $1; } - | Col AS AttrIdentifier ',' SelectList + | Col AS AttrIdentifier { - printf("SelectList 4\n"); - $$ = create_rename_operator($1, create_as_operator($3, $5)); + printf("SelectListElem 2\n"); + $$ = create_rename_operator($1, $3); } | AttrIdentifier { - printf("SelectList 1\n"); - $$ = create_rename_operator($1, NULL); + printf("SelectListElem 3\n"); + $$ = $1; } | AttrIdentifier AS AttrIdentifier { - printf("SelectList 2\n"); - $$ = create_as_operator($1, $3); - } - | AttrIdentifier ',' SelectList - { - printf("SelectList 3\n"); - $$ = create_rename_operator($1, $2); - } - | AttrIdentifier AS AttrIdentifier ',' SelectList - { - printf("SelectList 4\n"); - $$ = create_rename_operator($1, create_as_operator($3, $5)); + printf("SelectListElem 4\n"); + $$ = create_rename_operator($1, $3); } ; diff --git a/SQLPParserTests/TranslationQuery1 b/SQLPParserTests/TranslationQuery1 index 5f63cbc9614c92d604ee9b074f8e7e8bfd8bae25..450426fe28032ea0863429c723ade7c24511f409 100644 --- a/SQLPParserTests/TranslationQuery1 +++ b/SQLPParserTests/TranslationQuery1 @@ -1 +1 @@ -select x.ssn_num from Person x where x.std_info.name = "A" \ No newline at end of file +select x.ssn_num, x.age from Person x where x.std_info.name = "A" diff --git a/util.c b/util.c index f3ea6519eaeeba3af7d192c87f27f9762fb0b98d..51a29c99a122821c2c92f1ebc12774f2a87b678a 100644 --- a/util.c +++ b/util.c @@ -87,6 +87,13 @@ cons_cell* create_spcol(cons_cell* var, cons_cell* pf) { return operator_cons; } +cons_cell* create_select_list(cons_cell* elem, cons_cell* lst) { + cons_cell* lst_cons = create_cons_cell(elem, lst); + char operator[] = "SELECT_LIST\0"; + cons_cell* select_list_cons = create_cons_cell_w_atom(operator, lst_cons); + return select_list_cons; +} + cons_cell* create_pf(cons_cell* attr, cons_cell* next_attr) { cons_cell* attr_cons = create_cons_cell(attr, next_attr); char operator[3] = "PF\0"; @@ -419,7 +426,6 @@ void print_cons_tree_helper(cons_cell *root, int indent) { printf("\n"); print_cons_tree_helper(root->cdr, indent+1); } else { - cons_cell* tmp = (cons_cell*)root->car; print_cons_tree_helper((cons_cell*)root->car, indent); print_cons_tree_helper(root->cdr, indent); } @@ -558,7 +564,6 @@ cons_list *list_tables_helper(cons_cell *root, cons_list *tablelst) { } list_tables_helper(root->cdr, tablelst); } else { - cons_cell* tmp = (cons_cell*)root->car; list_tables_helper((cons_cell*)root->car, tablelst); list_tables_helper(root->cdr, tablelst); } diff --git a/util.h b/util.h index 428629ed9117fcb1831afc7ec640310df241c1c8..efa7571e45e83bb77d7a75778b3d762bc90445b7 100644 --- a/util.h +++ b/util.h @@ -77,6 +77,7 @@ algebra expressions for SQL queries: // The following are all helper functions to create the // various relational algebra expressions cons_cell* create_spcol(cons_cell* var, cons_cell* pf); +cons_cell* create_select_list(cons_cell* elem, cons_cell* lst); cons_cell* create_pf(cons_cell* attr, cons_cell* next_attr); cons_cell* create_table(char *table); cons_cell* create_term(cons_cell *term);