-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyesml.rbnf
99 lines (66 loc) · 3.78 KB
/
yesml.rbnf
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
START : <BOF> Top <EOF>;
Top : !stmts=Stmts -> Top(list(stmts));
Stmts : !a=Stmt -> Cons(a, nil);
Stmts : !a=Stmt !b=Stmts -> Cons(a, b);
Stmt : !it=(Let | Do | Open) -> it;
Do : 'do' !exp=Exp -> Do(exp);
Let : 'let' 'rec' !it=LetSeq -> Let(MKLRCommaList(it), true);
Let : 'let' !it=LetSeq -> Let(MKLRCommaList(it), false);
Bind : !ident=Id '=' !exp=Exp -> Bind(ident, exp);
LetSeq : [LetSeq 'and'] Bind;
Open : 'open' !ident=Id -> OpenId(ident);
Open : 'open' !string=<str> -> OpenString(MKStr(string));
Exp : !it=BlockExp -> BlockExpr(MKLRCommaList(it));
BlockExp : [BlockExp ';'] OrExp;
OrExp : !it=OrExpRoot -> Or(MKLRCommaList(it));
OrExpRoot : [OrExpRoot '||'] AndExp;
AndExp : !it=AndExpRoot -> And(MKLRCommaList(it));
AndExpRoot : [AndExpRoot '&&'] BinOp;
BinOp : !it=(App | LetExp | IfExp) -> it;
BinOp : !left=BinOp '`' !op=Id '`' !right=(App | LetExp | IfExp) -> App(op, Tuple2(left, right));
CommaExps : [CommaExps ','] Exp;
LetExp : !let=Let 'in' !exp=Exp -> LetExp(let, exp);
IfExp : 'if' !cond=Exp 'then' !tC=Exp 'else' !fC=Exp -> IfExp(cond, tC, fC);
App : !a=AtomExp -> a;
App : !f=App '(' !args=CommaExps ')' -> App(f, MKLRCommaList(args));
App : !f=App '(' ')' -> App(f, Tuple0);
App : !f=App !arg=Lit -> App(f, Tuple1(arg));
AtomExp : !it=(Lam | Match | Nest) -> it;
Lam : ('fn' | 'fun') '(' !args=CommaIds ')' '->' !exp=Exp ['end'] -> Lam(MKLRCommaList(args), exp);
Lam : ('fn' | 'fun') !arg=Id '->' !exp=Exp ['end'] -> Lam(Tuple1(arg), exp);
Lam : ('fn' | 'fun') '(' ')' '->' !exp=Exp ['end'] -> Lam(Tuple0, exp);
Id : !a=<identifier> -> MKIdent(a);
Ids : !hd=Id -> Cons(hd, nil);
Ids : !hd=Id !tl=Ids -> Cons(hd, tl);
CommaIds : [CommaIds ','] Id;
SymExpr : !a=<sym> -> SymExpr(MKSym(a));
ChrExpr : !a=<chr> -> ChrExpr(MKStr(a));
NumExpr : !a=<number> -> NumExpr(MKNum(a));
StrExpr : !a=<str> -> StrExpr(MKStr(a));
BoolExpr : !a=('true'|'false') -> BoolExpr(MKBool(a));
Nest : '(' !hd=Exp ')' -> hd;
Nest : !hd=Lit -> hd;
Lit : !a=(Id | SymExpr | BoolExpr | NumExpr | StrExpr | ChrExpr | List) -> a;
List : '[' !a=CommaExps <cons> !tl=Exp ']' -> List(MKLRCommaList(a), tl);
List : '[' !a=CommaExps ']' -> List(MKLRCommaList(a), none);
List : '[' ']' -> List(Tuple0, none);
Match : "match" !exp=Exp "with" !cases=CaseExps ['end']
-> Match(exp, MKLRList(cases));
CaseExps : [CaseExps] CaseExp;
CaseExp : '|' !case=Case '->' !exp=Exp -> Tuple3(case, none, exp);
CaseExp : '|' !case=Case 'when' !guard=Exp '->' !exp=Exp -> Tuple3(case, guard, exp);
Case : !a=OrCase -> MKOrCase(MKLRCommaList(a));
OrCase : [OrCase '|'] AndCaseRoot;
AndCaseRoot : !a=AndCase -> MKAndCase(MKLRCommaList(a));
AndCase : [AndCase '&'] AtomCase;
CommaCases : [CommaCases ','] Case;
AtomCase : !a=(NumCase | SymCase | BoolCase | ChrCase | StrCase | ListCase | NestCase | Id) -> a;
SymCase : !a=<sym> -> SymCase(MKSym(a));
ChrCase : !s=<chr> -> ChrCase(MKStr(s));
NumCase : !n=<number> -> NumCase(MKNum(n));
StrCase : !s=<str> -> StrCase(MKStr(s));
BoolCase : !a=('true'|'false') -> BoolCase(MKBool(a));
ListCase : '[' !a=CommaCases <cons> !tl=Case ']' -> ListCase(MKLRCommaList(a), tl);
ListCase : '[' !a=CommaCases ']' -> ListCase(MKLRCommaList(a), none);
ListCase : '[' ']' -> ListCase(Tuple0, none);
NestCase : '(' !hd=Case ')' -> hd;