Skip to content
Snippets Groups Projects
Commit d2e0a366 authored by Wanxin Li's avatar Wanxin Li
Browse files

changed grammar rules after June12 discussion

parent 32e1c17b
No related branches found
No related tags found
No related merge requests found
.DS_Store 0 → 100644
File added
%{
#include "util.h"
%}
%define api.value.type {cons_cell *}
%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
%%
/*
todo: add ELIM, LIMIT
todo: check recursive token is on the left
*/
SQLPProgram
: Query
{
printf("Input Query\n");
cons_cell *n = $1;
printf("Printing Tree\n");
print_cons_tree(n);
}
;
Query
: Union_Query
{
printf("Union Query\n");
$$ = $1;
}
| Union_Query Limit Constant // todo: limit by or limit?
| Select_Query
{
printf("Select Query\n");
$$ = $1;
}
|Select_Query Limit Constant
;
Select_Query // 4 possibilities
: SELECT Select_List Body
{
printf("SQLP Query\n");
$$ = create_proj_operator($2, $3);
}
;
Elim
: ELIM
| NO_ELM
;
Limit
: LIMIT
| NO_LIMIT
;
Body
: FROM TableList
{
printf("Body 1\n");
$$ = $2;
}
| FROM TableList WHERE Pred
{
printf("Body 2\n");
$$ = create_eval_operator($4, $2);
}
;
TableList
: TableIdentifier VarIdentifier
{
printf("TableList 1\n");
$$ = create_rename_operator($1, $2);
}
| TableIdentifier VarIdentifier ',' TableList // keep right-recursive
{
printf("TableList 2\n");
$$ = create_cross_operator(create_rename_operator($1, $2), $4); //
}
;
Union_Query
: '(' Select_Query ')' UNION Union_Query
{
printf("Union query\n");
$$ = create_union_all_operator($1, $3); // todo: create_union_operator
}
| '(' Select_Query ')' UNIONALL Union_Query
: Select_Query
;
Select_List
: Col
{
printf("Select_List 2\n");
$$ = create_rename_operator($1, NULL);
}
| Col as AttrIdentifier
| Col ',' Select_List
{
printf("Select_List 4\n");
$$ = create_rename_operator($1, $2);
}
| Col as AttrIdentifier ',' Select_List
; // todo: left_recursive
Col
: VarIdentifier '.' AttrPath
{
printf("col\n");
$$ = create_spcol($1, $3);
}
AttrPath
: AttrIdentifier
{
printf("AttrPath 1\n");
$$ = create_pf($1, NULL);
}
| AttrIdentifier '.' AttrPath
{
printf("AttrPath 2\n");
$$ = create_pf($1, $3);
}
VarIdentifier
: IDENTIFIER
{
printf("VarIdentifier is |%s| ", yytext);
$$ = create_var(yytext);
}
TableIdentifier
: IDENTIFIER
{
printf("TableIdentifier is |%s| ", yytext);
$$ = create_var(yytext);
}
AttrIdentifier
: IDENTIFIER
{
printf("AttrIdentifier is |%s| ", yytext);
$$ = create_var(yytext);
}
CompOperator
: EQ
{
printf("Operator EQ\n");
$$ = create_op(yytext);
}
| NE
{
printf("Operator NE\n");
$$ = create_op(yytext);
}
| LE
{
printf("Operator LE\n");
$$ = create_op(yytext);
}
| GE
{
printf("Operator GE\n");
$$ = create_op(yytext);
}
| LT
{
printf("Operator LT\n");
$$ = create_op(yytext);
}
| GT
{
printf("Operator GT\n");
$$ = create_op(yytext);
}
;
Pred
: Conj
| Pred OR Conj
| BasicPred
| Conj AND BasicPred
BasicPred
: Term CompOperator Term
| EXIST '(' Body ')'
| NOT BasicPred
| '(' Pred ')'
Term
: Constant
| TableList
Constant
: INTEGER
{
printf("INTEGER is |%s|", yytext);
$$ = create_constant(yytext);
}
| REAL
{
printf("REAL is |%s|", yytext);
$$ = create_constant(yytext);
}
| STRING
{
printf("STRING is |%s|", yytext);
$$ = create_constant(yytext);
}
;
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