Skip to content
Snippets Groups Projects
Commit 184237d9 authored by JasonJPu's avatar JasonJPu
Browse files

Add comments

parent 8111620d
No related branches found
No related tags found
1 merge request!1SQLP parser with cons cells
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 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 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 code in the C programming language: n "module" files with a ".c" suffix that
......
...@@ -7,52 +7,31 @@ ...@@ -7,52 +7,31 @@
#include <string.h> #include <string.h>
#include <assert.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 { typedef struct atom {
char* val; char* val;
} atom; } atom;
// A linked list like structure
// car points to element the node is holding // car points to element the node is holding
// cdr points to next cons cell in list or null // cdr points to next cons cell in list or null
// is_atom determines if car is an atom
typedef struct cons_cell { typedef struct cons_cell {
void* car; void* car;
struct cons_cell* cdr; struct cons_cell* cdr;
bool is_atom; bool is_atom;
} cons_cell; } cons_cell;
// Creates a cons_cell
enum type {
SQLPProgram,
Identifier,
Query,
Select_Query,
Body,
TablePath,
Union_Query,
Select_List,
AttrPath,
Operator,
Bool,
Pred
};
cons_cell* create_cons_cell(void* car, cons_cell* cdr); cons_cell* create_cons_cell(void* car, cons_cell* cdr);
// Creates an atom
atom* create_atom(char* val); 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); 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_spcol(cons_cell* var, cons_cell* pf);
cons_cell* create_pf(cons_cell* attr, cons_cell* next_attr); cons_cell* create_pf(cons_cell* attr, cons_cell* next_attr);
cons_cell* create_table(char *table); cons_cell* create_table(char *table);
...@@ -73,14 +52,8 @@ cons_cell* create_limit_operator(cons_cell* ra1, cons_cell* ra2); ...@@ -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_elim_operator(cons_cell* ra1, cons_cell* ra2);
cons_cell* create_eval_operator(cons_cell* logic, cons_cell* cross); cons_cell* create_eval_operator(cons_cell* logic, cons_cell* cross);
struct node *new_node(int count, int type); // Prints an in order traversal of the tree
void translate(struct linked_node *linked_tree, struct node *tree);
void print_cons_tree(cons_cell *root, int indent); 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 #endif
......
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