BadgerDB
|
00001 #ifndef PARSE_H 00002 #define PARSE_H 00003 00004 00005 00006 // 00007 // ATTR_DESCR: attribute descriptor 00008 // 00009 00010 typedef struct { 00011 char *attrName; // relation name 00012 int attrType; // type of attribute 00013 int attrLen; // length of attribute 00014 } ATTR_DESCR; 00015 00016 00017 // 00018 // REL_ATTR: describes a qualified attribute (relName.attrName) 00019 // 00020 00021 typedef struct { 00022 char *relName; // relation name 00023 char *attrName; // attribute name 00024 } REL_ATTR; 00025 00026 // 00027 // ATTR_VAL: <attribute, value> pair 00028 // 00029 00030 typedef struct { 00031 char *attrName; // attribute name 00032 int valType; // type of value 00033 int valLength; // length if type = STRING_TYPE 00034 void *value; // value for attribute 00035 } ATTR_VAL; 00036 00037 00038 #define INTCHAR 'i' 00039 #define FLOATCHAR 'f' 00040 #define STRCHAR 's' 00041 #define PROMPT "\n>>> " 00042 00043 00044 // 00045 // all the available kinds of nodes 00046 // 00047 00048 typedef enum { 00049 N_QUERY, 00050 N_INSERT, 00051 N_DELETE, 00052 N_CREATE, 00053 N_DESTROY, 00054 N_BUILD, 00055 N_REBUILD, 00056 N_DROP, 00057 N_LOAD, 00058 N_PRINT, 00059 N_HELP, 00060 N_SELECT, 00061 N_JOIN, 00062 N_PRIMATTR, 00063 N_QUALATTR, 00064 N_ATTRVAL, 00065 N_ATTRTYPE, 00066 N_VALUE, 00067 N_LIST 00068 } NODEKIND; 00069 00070 00071 // 00072 // structure of parse tree nodes 00073 // 00074 00075 typedef struct node { 00076 NODEKIND kind; 00077 00078 union { 00079 // query node */ 00080 struct { 00081 char *relname; 00082 struct node *attrlist; 00083 struct node *qual; 00084 } QUERY; 00085 00086 // insert node */ 00087 struct { 00088 char *relname; 00089 struct node *attrlist; 00090 } INSERT; 00091 00092 // delete node */ 00093 struct { 00094 char *relname; 00095 struct node *qual; 00096 } DELETE; 00097 00098 // create node */ 00099 struct { 00100 char *relname; 00101 struct node *attrlist; 00102 struct node *primattr; 00103 } CREATE; 00104 00105 // destroy node */ 00106 struct { 00107 char *relname; 00108 } DESTROY; 00109 00110 // re/build node */ 00111 struct { 00112 char *relname; 00113 char *attrname; 00114 int nbuckets; 00115 } BUILD; 00116 00117 // drop node */ 00118 struct { 00119 char *relname; 00120 char *attrname; 00121 } DROP; 00122 00123 // load node */ 00124 struct { 00125 char *relname; 00126 char *filename; 00127 } LOAD; 00128 00129 // pprint node */ 00130 struct { 00131 char *relname; 00132 } PRINT; 00133 00134 // help node */ 00135 struct { 00136 char *relname; 00137 } HELP; 00138 00139 // select node */ 00140 struct { 00141 struct node *selattr; 00142 int op; 00143 struct node *value; 00144 } SELECT; 00145 00146 // join node */ 00147 struct { 00148 struct node *joinattr1; 00149 int op; 00150 struct node *joinattr2; 00151 } JOIN; 00152 00153 // qualified attribute node */ 00154 struct { 00155 char *relname; 00156 char *attrname; 00157 } QUALATTR; 00158 00159 // primary attribute node */ 00160 struct { 00161 char *attrname; 00162 int nbuckets; 00163 } PRIMATTR; 00164 00165 // <attribute, value> pair */ 00166 struct { 00167 char *attrname; 00168 struct node *value; 00169 } ATTRVAL; 00170 00171 // <attribute, type> pair */ 00172 struct { 00173 char *attrname; 00174 char *type; 00175 } ATTRTYPE; 00176 00177 // <value, type> pair */ 00178 struct { 00179 int type; 00180 int len; 00181 union { 00182 int ival; 00183 float rval; 00184 char *sval; 00185 } u; 00186 } VALUE; 00187 00188 // list node */ 00189 struct { 00190 struct node *self; 00191 struct node *next; 00192 } LIST; 00193 } u; 00194 } NODE; 00195 00196 00197 // 00198 // function prototypes 00199 // 00200 00201 NODE *newnode(int kind); 00202 NODE *query_node(char *relname, NODE *attrlist, NODE *n); 00203 NODE *insert_node(char *relname, NODE *attrlist); 00204 NODE *delete_node(char *relname, NODE *qual); 00205 NODE *create_node(char *relname, NODE *attrlist, NODE *primattr); 00206 NODE *destroy_node(char *relname); 00207 NODE *build_node(char *relname, char *attrname, int nbuckets); 00208 NODE *rebuild_node(char *relname, char *attrname, int nbuckets); 00209 NODE *drop_node(char *relname, char *attrname); 00210 NODE *load_node(char *relname, char *filename); 00211 NODE *print_node(char *relname); 00212 NODE *help_node(char *relname); 00213 NODE *select_node(NODE *selattr, int op, NODE *value); 00214 NODE *join_node(NODE *joinattr1, int op, NODE *joinattr2); 00215 NODE *qualattr_node(char *relname, char *attrname); 00216 NODE *primattr_node(char *attrname, int nbuckets); 00217 NODE *attrval_node(char *attrname, NODE *value); 00218 NODE *attrtype_node(char *attrname, char *type); 00219 NODE *int_node(int ival); 00220 NODE *float_node(float rval); 00221 NODE *string_node(char *s); 00222 NODE *list_node(NODE *n); 00223 NODE *prepend(NODE *n, NODE *list); 00224 00225 #endif