-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathebnf.y
66 lines (54 loc) · 1.14 KB
/
ebnf.y
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
/* EBNF grammar spec */
%lex
id [a-zA-Z][a-zA-Z0-9_-]*
%%
\s+ /* skip whitespace */
{id} return 'symbol';
"["{id}"]" yytext = yytext.substr(1, yyleng-2); return 'ALIAS';
"'"[^']*"'" return 'symbol';
"." return 'symbol';
bar return 'bar';
"(" return '(';
")" return ')';
"*" return '*';
"?" return '?';
"|" return '|';
"+" return '+';
<<EOF>> return 'EOF';
/lex
%start production
%%
production
: handle EOF
{ return $handle; }
;
handle_list
: handle
{ $$ = [$handle]; }
| handle_list '|' handle
{ $handle_list.push($handle); }
;
handle
:
{ $$ = []; }
| handle expression_suffix
{ $handle.push($expression_suffix); }
;
expression_suffix
: expression suffix ALIAS
{ $$ = ['xalias', $suffix, $expression, $ALIAS]; }
| expression suffix
{ if ($suffix) $$ = [$suffix, $expression]; else $$ = $expression; }
;
expression
: symbol
{ $$ = ['symbol', $symbol]; }
| '(' handle_list ')'
{ $$ = ['()', $handle_list]; }
;
suffix
:
| '*'
| '?'
| '+'
;