Skip to content
Snippets Groups Projects
Commit 00abfd86 authored by Tony Zhang's avatar Tony Zhang
Browse files

Ref Exp

parent 8719f3bb
No related branches found
No related tags found
1 merge request!6Rewrite Parsers for SQLP Query, Schema, and Referring Type Expression
......@@ -21,63 +21,68 @@
SQLPRefExp
: RefExpTypeComponentList
{
$$ = $1;
$$ = create_cons_cell_w_atom("SQLP_REF_EXP", create_list("REF_EXP_TYPE_COMPONENT", $1));
};
RefExpTypeComponentList
: RefExpTypeComponentList ';' RefExpTypeComponent
: RefExpTypeComponent ';' RefExpTypeComponentList
{
$$ = NULL;
cdr($1) = $3;
$$ = $1;
}
| RefExpTypeComponent
{
$$ = NULL;
$$ = $1;
};
RefExpTypeComponent
: Guard REF AttributePath
{
$$ = NULL;
cdr($1) = $3;
$$ = create_cons_cell_w_atom("REF_EXP_TYPE_COMPONENT", $1);
}
| Guard REF '(' AttributePathList ')'
{
$$ = NULL;
cdr($1) = $4;
$$ = create_cons_cell_w_atom("REF_EXP_TYPE_COMPONENT", $1);
};
Guard
: TableIdentifier
{
$$ = NULL;
$$ = create_cons_cell_w_atom("GUARD", $1);
};
AttributePathList
: AttributePathList ',' AttributePath
: AttributePath ',' AttributePathList
{
$$ = NULL;
cdr($1) = $3;
$$ = $1;
}
| AttributePath
{
$$ = NULL;
$$ = create_list("ATTRIBUTE", $1);
};
AttributePath
: AttributePath '.' AttributeIdentifier
: AttributeIdentifier '.' AttributePath
{
$$ = NULL;
cdr($1) = $3;
$$ = $1;
}
| AttributeIdentifier
{
$$ = NULL;
$$ = $1;
};
AttributeIdentifier
: IDENTIFIER
{
$$ = NULL;
$$ = create_identifier("ATTRIBUTE\0", $1);
}
TableIdentifier
: IDENTIFIER
{
$$ = NULL;
$$ = create_identifier("TABLE\0", $1);
};
......@@ -11,7 +11,7 @@ cons_cell* create_cons_cell(void* car, cons_cell* cdr) {
atom* create_atom(char* val) {
printf("create_atom: %s\n", val);
// printf("create_atom: %s\n", val);
atom* new_atom = malloc(sizeof(atom));
new_atom->val = malloc(sizeof(char) * (strlen(val) + 1));
strcpy(new_atom->val, val);
......@@ -28,10 +28,45 @@ cons_cell* create_cons_cell_w_atom(char* val, cons_cell* cdr) {
return new_cons;
}
void * car(cons_cell * cc) {
void *& car(cons_cell * cc) {
return cc->car;
}
void * cdr(cons_cell * cc) {
cons_cell *& cdr(cons_cell * cc) {
return cc->cdr;
}
cons_cell* create_table_identifier(char *type, char *identifier) {
char str[100];
strcpy(str, type);
strcat(str, "_IDENTIFIER\0");
cons_cell* cc = create_cons_cell_w_atom(identifier, NULL);
return create_cons_cell_w_atom(str, cc);
}
cons_cell * create_list(char *type, cons_cell *list) {
char str[100];
strcpy(str, type);
strcat(str, "_LIST\0");
return create_cons_cell(str, list);
}
static void print_cons_tree_helper(cons_cell *cc, unsigned int padding) {
if (cc == NULL) {
return;
}
if (cc->is_atom) {
for (unsigned int i = 0; i < padding; ++i) {
printf(" ");
}
printf("%s\n", ((atom*) car(cc))->val);
print_cons_tree_helper(cdr(cc), padding);
} else {
print_cons_tree_helper(car(cc), padding + 2);
print_cons_tree_helper(cdr(cc), padding);
}
}
void print_cons_tree(cons_cell *cc) {
print_cons_tree_helper(cc, 0);
}
......@@ -29,8 +29,14 @@ 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);
void * car(cons_cell * cc);
void *& car(cons_cell * cc);
void * cdr(cons_cell * cc);
cons_cell *& cdr(cons_cell * cc);
cons_cell * create_identifier(char *type, char *identifier);
cons_cell * create_list(char *type, cons_cell *list);
void print_cons_tree(cons_cell *cc);
#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