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

Fix repo

parent c4a877ee
No related branches found
No related tags found
1 merge request!1SQLP parser with cons cells
%{
#include "util.h"
%}
// %union {
// struct node *n;
//}
%define api.value.type {struct node *}
%token IMPLIES OR AND NOT LE GE LT GT NE HAS MAX MIN AS ASC DESC MOD ASSIGN EQ STAR COMMA DOT
%token SIZE SELECTIVITY OVERLAP
%token FREQUENCY UNIT TIME SPACE
%token IDENTIFIER CONSTANT STRING_LITERAL SIZEOF
%token STORE STORING DYNAMIC STATIC OF TYPE ORDERED BY
%token INDEX LIST ARRAY BINARY TREE DISTRIBUTED POINTER
%token SCHEMA CLASS ISA PROPERTIES CONSTRAINTS PROPERTY
%token ON DETERMINED COVER QUERY GIVEN FROM SELECT WHERE ORDER
%token PRECOMPUTED ONE EXIST FOR ALL TRANSACTION INTCLASS STRCLASS
%token INTEGER REAL DOUBLEREAL STRING MAXLEN RANGE TO
%token INSERT END CHANGE DELETE DECLARE RETURN UNION
%start SQLPProgram
%%
SQLPProgram
: Query
{ printf("Input Query\n");
struct node *n = new_node(1, SQLPProgram);
n->children[0] = $1;
printf("Printing Tree\n");
print_tree(n, 0);
struct linked_node *linked_tree = malloc(sizeof(struct linked_node));
translate(linked_tree, n);
print_linked_tree(linked_tree, 0);
}
;
Identifier
: IDENTIFIER
{ printf("|%s| ", yytext);
$$ = new_node(1, Identifier);
$$->children[0] = new_node(0, IDENTIFIER);
}
;
Query
: Union_Query
{ printf("Union Query\n");
$$ = new_node(1, Query);
$$->children[0] = $1;
}
;
Select_Query
: SELECT Select_List Body
{ printf("SQLP Query\n");
$$ = new_node(3, Select_Query);
$$->children[0] = new_node(0, SELECT);
$$->children[1] = $2;
$$->children[2] = $3;
}
;
Body
: FROM TablePath
{ printf("Body 1\n");
$$ = new_node(2, Body);
$$->children[0] = new_node(0, FROM);
$$->children[1] = $2;}
| FROM TablePath WHERE Bool
{ printf("Body 2\n");
$$ = new_node(4, Body);
$$->children[0] = new_node(0, FROM);
$$->children[1] = $2;
$$->children[2] = new_node(0, WHERE);
$$->children[3] = $4;
}
| FROM TablePath WHERE Pred
{ printf("Body 3\n");
$$ = new_node(4, Body);
$$->children[0] = new_node(0, FROM);
$$->children[1] = $2;
$$->children[2] = new_node(0, WHERE);
$$->children[3] = $4;
}
;
TablePath
: Identifier Identifier RA
{ printf("last table path\n");
# Chance depending on how we change Identifier to need to change $1 to $1->name $2->name or smth
$$ = create_cons_cell(create_table_assignment($1, $2), $3);
}
| Identifier Identifier ',' TablePath
{ printf("Table path and more\n");
$$ = create_cons_cell(create_table_assignment($1, $2), $4);
}
;
Union_Query
: Select_Query
{ printf("union query 1\n");
$$ = new_node(1, Union_Query);
$$->children[0] = $1;
}
| Union_Query UNION Select_Query
{ printf("union query 2\n");
$$ = new_node(3, Union_Query);
$$->children[0] = $1;
$$->children[1] = new_node(0, UNION);
$$->children[2] = $3;
}
;
Select_List
: STAR
{ printf("star\n");
$$ = new_node(1, Select_List);
$$->children[0] = new_node(0, STAR);
}
| AttrPath
{ printf("select list attr path\n");
$$ = new_node(1, Select_List);
$$->children[0] = $1;
}
| AttrPath ',' Select_List
{ printf("Select list\n");
$$ = new_node(3, Select_List);
$$->children[0] = $1;
$$->children[1] = new_node(0, COMMA);
$$->children[2] = $3;
}
;
AttrPath
: Identifier
{ printf("path id\n");
$$ = new_node(1, AttrPath);
$$->children[0] = $1;
}
| Identifier '.' AttrPath
{ printf("Path Function\n");
$$ = new_node(3, AttrPath);
$$->children[0] = $1;
$$->children[1] = new_node(0, DOT);
$$->children[2] = $3;
}
;
Operator
: EQ
| NE
| LE
| GE
| LT
| GT
;
Bool
: AttrPath Operator AttrPath
{ printf("AttrPath op AttrPath\n");
$$ = create_comp_operator($2, $1, $3, NULL);
}
| AttrPath Operator CONSTANT
{ printf("AttrPath op Constant\n");
cons_cell* a = create_cons_cell_w_atom(CONSTANT, NULL);
$$ = create_comp_operator($2, $1, a, NULL);
}
;
Pred
: Bool AND Pred
{ printf("pred and pred\n");
$$ = $1;
$$->cdr->cdr->cdr->cdr->car = $3;
}
| NOT Pred
{ printf("Not Pred\n");
$$ = create_not_operator($1, NULL);
}
| EXIST '(' Query ')'
{ printf("Exist query\n");
$$ = new_node(2, Pred);
$$->children[0] = new_node(0, EXIST);
$$->children[1] = $3;
}
;
......@@ -85,19 +85,14 @@ Body
;
TablePath
: Identifier Identifier
{ printf("table path1\n");
$$ = new_node(2, TablePath);
$$->children[0] = $1;
$$->children[1] = $2;
}
: Identifier Identifier RA
{ printf("last table path\n");
# Chance depending on how we change Identifier to need to change $1 to $1->name $2->name or smth
$$ = create_cons_cell(create_table_assignment($1, $2), $3);
}
| Identifier Identifier ',' TablePath
{ printf("table path2\n");
$$ = new_node(4, TablePath);
$$->children[0] = $1;
$$->children[1] = $2;
$$->children[2] = new_node(0, COMMA);
$$->children[3] = $4;
{ printf("Table path and more\n");
$$ = create_cons_cell(create_table_assignment($1, $2), $4);
}
;
......@@ -175,4 +170,4 @@ Pred
$$->children[0] = new_node(0, EXIST);
$$->children[1] = $3;
}
;
\ No newline at end of file
;
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