-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.y
More file actions
80 lines (69 loc) · 1.9 KB
/
test.y
File metadata and controls
80 lines (69 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
%{
#include "test_translator.h"
extern int yylex();
void yyerror(char* s);
%}
%union
{
char* str;
Node* node;
}
%token AND OR SELECT PROJECT JOIN UNION INTERSECT DIFF PROD LSQ RSQ LPAR RPAR NL
%token <str> WORD
%start result
%type<node>
expression
table
term
%%
result :
| result table
{ revert($2); }
| result table NL
{ revert($2); cout << endl; }
| result error NL
{ }
;
table : term
{ $$ = makeTree($1); }
| LPAR table RPAR
{ $$ = $2; }
| SELECT LSQ expression RSQ LPAR table PROD table RPAR
{ $$ = joinTree($3, $6, $8); }
| SELECT LSQ expression RSQ LPAR table JOIN LSQ expression RSQ table RPAR
{ $$ = joinTree(appendAndNode($3, $9), $6, $11); }
| SELECT LSQ expression RSQ LPAR table DIFF table RPAR
{ $$ = diffTree($3, $6, $8); }
| SELECT LSQ expression RSQ LPAR table RPAR
{ $$ = makeSelectTree($3, $6); }
| PROJECT LSQ expression RSQ LPAR table RPAR
{ $$ = makeProjectTree($3, $6); }
| PROJECT LSQ expression RSQ LPAR table UNION table RPAR
{ $$ = unionTree($3, $6, $8); }
| table INTERSECT table
{ $$ = intersectTree($1, $3); }
| table UNION table
{ $$ = unionTree(NULL, $1, $3); }
| table DIFF table
{ $$ = diffTree(NULL, $1, $3); }
| table JOIN LSQ expression RSQ table
{ $$ = joinTree($4, $1, $6); }
;
expression: term
{ $$ = $1; }
| expression AND term
{ $$ = makeAndNode($1, $3); }
;
term: WORD
{ $$ = makeTermNode($1); }
| term OR WORD
{
string s = ($1)->content + " OR " + $3;
$$ = makeTermNode(s);
}
;
%%
void yyerror(char* s)
{
cout << "Error Detected : " << s << endl;
}