-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.jison
More file actions
53 lines (44 loc) · 910 Bytes
/
grammar.jison
File metadata and controls
53 lines (44 loc) · 910 Bytes
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
/* lexical grammar */
%lex
%%
\s+ /* skip whitespace */
"and" return "AND"
"or" return "OR"
"not" return "NOT"
[a-zA-Z0-9\-]+ return "TAG"
"(" return "("
")" return ")"
<<EOF>> return "EOF"
. return "INVALID"
/lex
/* operator associations and precedence */
%left "OR"
%left "AND"
%right "NOT"
%start expressions
%% /* language grammar */
expressions
: e EOF
{ return $1; }
;
e
: e "OR" e
{ $$ = {type: "or", left: $1, right: $3}; }
| e "AND" e
{ $$ = {type: "and", left: $1, right: $3}; }
| "NOT" e
{{
$$ = $2;
$$.not = !$$.not;
}}
| "(" e ")"
{ $$ = $2; }
| compound-tag
{ $$ = {type: "tag", tag: $1}; }
;
compound-tag
: compound-tag TAG
{ $$ = $1 + " " + $2; }
| TAG
{ $$ = $1; }
;