-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgrammar.jison
More file actions
41 lines (33 loc) · 785 Bytes
/
grammar.jison
File metadata and controls
41 lines (33 loc) · 785 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
%lex
%%
"{"[^}]*"}" /* skip comment */
"#".* /* skip comment */
\s+ /* skip whitespace */
[^{}#=;,:()\s]+ return "NAME";
"=" return "=";
";" return ";";
"," return ",";
":" return ":";
"(" return "(";
")" return ")";
<<EOF>> return "EOF";
/lex
%token NAME
%%
text : defs term EOF {return {macros: $1, term: $2};}
;
defs : /* empty */ {$$ = [];}
| defs NAME '=' term ';' {$1.unshift({id: $2, def: $4}); $$ = $1;}
;
term : appl
| abst
;
abst : NAME ',' abst {$$ = {node: "abst", bound: $1, body: $3};}
| NAME ':' term {$$ = {node: "abst", bound: $1, body: $3};}
;
appl : atom
| appl atom {$$ = {node: "appl", left: $1, right: $2};}
;
atom : '(' term ')' {$$ = $2;}
| NAME {$$ = {node: "atom", name: yytext};}
;