diff --git a/Makefile b/Makefile index 65ae0d6432bfe6dc1b973a39a450238439cd7959..b5708ad1b0fec52e2c1a7303b5327b39f229bc70 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ .PHONY: all clean - +#CFLAGS = `pkg-config --cflags glib-2.0` +#LDLIBS = `pkg-config --libs glib-2.0` all: SQLPParser - SQLPParser: SQLPParser.c SQLPGrammar.y SQLPScanner.l util.o bison --verbose -d SQLPGrammar.y flex SQLPScanner.l @@ -11,7 +11,8 @@ SQLPParser: SQLPParser.c SQLPGrammar.y SQLPScanner.l util.o util.o: util.c util.h gcc -c util.c - +# gcc `pkg-config --cflags --libs glib-2.0` util.c + #gcc -c util.c clean: rm -f lex.yy.c *.tab.c *.tab.h *.fasl util.o diff --git a/SQLPGrammar.y b/SQLPGrammar.y index f49c44a9d14fb2e11fae5bd364953f6a17f77ad7..f3f82a7ec723f96869f12e75b2adfa388a7fc41b 100644 --- a/SQLPGrammar.y +++ b/SQLPGrammar.y @@ -62,11 +62,11 @@ Body TablePath : TableIdentifier VarIdentifier { printf("last table path\n"); - $$ = create_atom_operator($1, $2); + $$ = create_assign_operator($1, $2); } | TableIdentifier VarIdentifier ',' TablePath { printf("table path2\n"); - $$ = create_cross_operator(create_atom_operator($1, $2), $4); + $$ = create_cross_operator(create_assign_operator($1, $2), $4); } ; @@ -89,11 +89,11 @@ Select_List } | Col { printf("select list attr path\n"); - $$ = create_assign_operator($1, NULL); + $$ = create_rename_operator($1, $1, NULL); } | Col ',' Select_List { printf("Select list\n"); - $$ = create_assign_operator($1, $2); + $$ = create_rename_operator($1, $1, $2); } ; diff --git a/SQLPParser b/SQLPParser index 324f5065f28f4d5a24995f15369ba5904c853ead..7f6390ffbfe91602bd2fb9c51bca1de56eff417d 100755 Binary files a/SQLPParser and b/SQLPParser differ diff --git a/util.c b/util.c index da4c089197d0cf67d88fbaa2efd076452d25dd96..f1e3d3752e099d6fd0ec6be4ca7c2213f7eeab22 100644 --- a/util.c +++ b/util.c @@ -121,10 +121,25 @@ cons_cell* create_cross_operator(cons_cell* ra1, cons_cell* ra2) { } // For when you want to assign column names to another name -cons_cell* create_assign_operator(cons_cell* spcol, cons_cell* next) { - cons_cell* sp_col_cons = create_cons_cell(spcol, next); +cons_cell* create_rename_operator(cons_cell* column, cons_cell* var, cons_cell* next) { + cons_cell* new_name_cons = create_cons_cell(var, next); + cons_cell* original_cons = create_cons_cell(column, new_name_cons); + char operator[7] = "RENAME\0"; + cons_cell* operator_cons = create_cons_cell_w_atom(operator, original_cons); + return operator_cons; +} + +// For when you want to assign a var to a table +cons_cell* create_assign_operator(cons_cell* table, cons_cell* var) { + // cdr to get to cons atom, car to get atom itself +// if(hash == NULL) +// hash = g_hash_table_new(g_str_hash, g_str_equal); + +// printf("test %s", ((atom*)table->cdr->car)->val); + cons_cell* new_name_cons = create_cons_cell(var, NULL); + cons_cell* original_cons = create_cons_cell(table, new_name_cons); char operator[3] = "AS\0"; - cons_cell* operator_cons = create_cons_cell_w_atom(operator, sp_col_cons); + cons_cell* operator_cons = create_cons_cell_w_atom(operator, original_cons); return operator_cons; } diff --git a/util.h b/util.h index 546116d11508a8b86b5fbd82abda29cbac4c89e9..ee3c774746a7feb8fd1d3e3d0f410e67c62616b9 100644 --- a/util.h +++ b/util.h @@ -6,7 +6,7 @@ #include <stdbool.h> #include <string.h> #include <assert.h> - +//#include <glib.h> // Basic building blocks that contain char values typedef struct atom { @@ -23,6 +23,8 @@ typedef struct cons_cell { bool is_atom; } cons_cell; +//static GHashTable* hash = NULL; + // Creates a cons_cell cons_cell* create_cons_cell(void* car, cons_cell* cdr); // Creates an atom diff --git a/util.o b/util.o index c13b8e103a91124d826e280bcb56ed9e3d096e7a..2fa3d8121cfea077faf3006291a71d604cddae08 100644 Binary files a/util.o and b/util.o differ