Skip to content
Snippets Groups Projects
Commit 4933c08d authored by expan's avatar expan
Browse files

Changed naming for select statements to be RENAME and for table assignment to...

Changed naming for select statements to be RENAME and for table assignment to be AS, also in-prog work for hash table (can't get glib to work for the life of me)
parent 184237d9
No related branches found
No related tags found
1 merge request!1SQLP parser with cons cells
.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
......@@ -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);
}
;
......
No preview for this file type
......@@ -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;
}
......
......@@ -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
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment