diff --git a/README.md b/README.md index 91067b91ece136ce68f141db200dcd3315691abe..210ac94be33f02a98fe6aeaff18bdd703de06355 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +To run the parser, run `make` then run `./SQLPParser`. An example of a test input is `select s.name from student s where s.name = "John";`. Currently a syntax error will be reported when the semi-colon is read, but the parse tree that is outputted is correct. + +The grammar is located in `SQLPGrammar.y`, and non-keyword types (such as `INTEGER`, `IDENTIFIER`, `STRING`) are defined in `SQLPScanner.l`. `util.c` contains the functions needed to build the con cell structure. + A common way of defining the behavior of a process or thread in cases where performance is critical is in terms of a collection of n+1 files containing code in the C programming language: n "module" files with a ".c" suffix that diff --git a/util.h b/util.h index 7f4ccc381dac0cc94e888e834f8c09f2a427aaf6..546116d11508a8b86b5fbd82abda29cbac4c89e9 100644 --- a/util.h +++ b/util.h @@ -7,52 +7,31 @@ #include <string.h> #include <assert.h> -struct node { - int type; - int count; - struct node **children; -}; - - -struct linked_node { - int type; - struct linked_node *next; // siblings - struct linked_node *children; -}; - +// Basic building blocks that contain char values typedef struct atom { char* val; } atom; - +// A linked list like structure // car points to element the node is holding // cdr points to next cons cell in list or null +// is_atom determines if car is an atom typedef struct cons_cell { void* car; struct cons_cell* cdr; bool is_atom; } cons_cell; - -enum type { - SQLPProgram, - Identifier, - Query, - Select_Query, - Body, - TablePath, - Union_Query, - Select_List, - AttrPath, - Operator, - Bool, - Pred -}; - +// Creates a cons_cell cons_cell* create_cons_cell(void* car, cons_cell* cdr); +// Creates an atom atom* create_atom(char* val); +// Creates a cons_cell that has an atom as its car cons_cell* create_cons_cell_w_atom(char* val, cons_cell* cdr); + +// 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_pf(cons_cell* attr, cons_cell* next_attr); cons_cell* create_table(char *table); @@ -73,14 +52,8 @@ cons_cell* create_limit_operator(cons_cell* ra1, cons_cell* ra2); cons_cell* create_elim_operator(cons_cell* ra1, cons_cell* ra2); cons_cell* create_eval_operator(cons_cell* logic, cons_cell* cross); -struct node *new_node(int count, int type); -void translate(struct linked_node *linked_tree, struct node *tree); - +// Prints an in order traversal of the tree void print_cons_tree(cons_cell *root, int indent); -void print_tree(struct node *root, int indent); -void print_linked_tree(struct linked_node *root, int indent); -void destroy_tree(struct node *root); -bool match(struct linked_node *pat, struct linked_node *tree); #endif