Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LDI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Grant Weddell
LDI
Commits
daccfc1d
Commit
daccfc1d
authored
6 years ago
by
JasonJPu
Browse files
Options
Downloads
Patches
Plain Diff
Update grammar
parent
026b7bcd
No related branches found
No related tags found
1 merge request
!1
SQLP parser with cons cells
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SQLPGrammer2.y
+194
-0
194 additions, 0 deletions
SQLPGrammer2.y
with
194 additions
and
0 deletions
SQLPGrammer2.y
+
194
−
0
View file @
daccfc1d
%{
#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
{ printf("table path1\n");
$$ = new_node(2, TablePath);
$$->children[0] = $1;
$$->children[1] = $2;
}
| 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;
}
;
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;
}
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment