-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrammar.cf
94 lines (70 loc) · 2.92 KB
/
Grammar.cf
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
ProgramDefs. Program ::= [Def] ;
terminator Def "" ;
DefFun. Def ::= "func" Id "(" [Arg] ")" "->" Type "{" [Stm] "}" ;
DefFunExposed. Def ::= "exposed" "func" Id "(" [Arg] ")" "->" Type "{" [Stm] "}" ;
DefTypedef. Def ::= "typedef" Ident "=" "union" Type "|" Type ;
separator Arg "," ;
terminator Stm "" ;
ArgDecl. Arg ::= Id ":" Type ;
StmInit. Stm ::= "let" IdMaybeTyped "=" Exp ;
StmSplit. Stm ::= "let" "(" IdMaybeTyped "," IdMaybeTyped ")" "=" Exp ;
StmIfElse. Stm ::= "if" "(" IfCond ")" "{" [Stm] "}" Else ;
StmSwitch. Stm ::= "switch" "(" Exp ")" "{" [SwitchCase] "}" ;
StmReturn. Stm ::= "return" Exp ;
StmAssert. Stm ::= Assertion ;
IdMaybeTypedNotTyped. IdMaybeTyped ::= Id ;
IdMaybeTypedTyped. IdMaybeTyped ::= Id ":" Type ;
IfCondCase. IfCond ::= "case" "let" IdMaybeTyped "=" Case Exp ;
IfCondBool. IfCond ::= Exp ;
IfCondUnfold. IfCond ::= "let" "(" IdMaybeTyped "," IdMaybeTyped ")" "=" "unfold" Exp ;
SwitchCaseDefault. SwitchCase ::= "case" "let" IdMaybeTyped "=" Case ":" "{" [Stm] "}" ;
separator nonempty SwitchCase "";
ElseNone. Else ::= ;
ElseStms. Else ::= "else" "{" [Stm] "}" ;
rules Case ::= "inl" | "inr" ;
ExpInt. Exp15 ::= Integer ;
ExpDouble. Exp15 ::= Double ;
ExpUnit. Exp15 ::= "(" ")" ;
ExpTrue. Exp15 ::= "true" ;
ExpFalse. Exp15 ::= "false" ;
ExpOption. Exp15 ::= "Just" "(" Exp ")" ;
ExpNothing.Exp15 ::= "Nothing" ;
ExpId. Exp15 ::= Id ;
ExpPair. Exp15 ::= "(" Exp "," Exp ")" ;
ExpSum. Exp15 ::= Ident "(" Case ":" Exp ")" ;
ExpList. Exp15 ::= "[" [Exp] "]" ;
ExpRef. Exp15 ::= "ref" "<" Type ">" "(" ")" ;
ExpApp. Exp15 ::= Id "(" [Exp] ")" ;
ExpNoising.Exp15 ::= "add_noise" "(" Exp ")" ;
ExpNegative. Exp14 ::= "-" Exp13 ;
ExpNot. Exp13 ::= "!" Exp14 ;
ExpTimes. Exp12 ::= Exp12 "*" Exp13 ;
ExpDiv. Exp12 ::= Exp12 "/" Exp13 ;
ExpPlus. Exp11 ::= Exp11 "+" Exp12 ;
ExpMinus. Exp11 ::= Exp11 "-" Exp12 ;
ExpLt. Exp9 ::= Exp9 "<" Exp10 ;
ExpGt. Exp9 ::= Exp9 ">" Exp10 ;
ExpLtEq. Exp9 ::= Exp9 "<=" Exp10 ;
ExpGtEq. Exp9 ::= Exp9 ">=" Exp10 ;
ExpEq. Exp8 ::= Exp8 "==" Exp9 ;
ExpNeq. Exp8 ::= Exp8 "!=" Exp9 ;
separator Exp "," ;
coercions Exp 15 ;
AssertionTypeEqual. Assertion ::= "assertTypeEqual" "(" Id "," Type ")" ;
TypeInitDouble. Type ::= CoreType "!" Double ;
TypeInitInt. Type ::= CoreType "!" Integer ;
TypeExponential. Type ::= CoreType "!" "inf" ;
CoreTypeBase. CoreType ::= BaseType ;
CoreTypeMulPair. CoreType ::= "(" Type "," Type ")" ;
CoreTypeSum. CoreType ::= "(" Type "+" Type ")" ;
CoreTypeList. CoreType ::= "[" Type "]" ;
CoreTypeNamed. CoreType ::= Ident Generics;
CoreTypeFunction.CoreType ::= "(" "(" [Type] ")" "->" Type ")" ;
GenericsNone. Generics ::= ;
GenericsType. Generics ::= "<" Type ">" ;
separator Type "," ;
rules BaseType ::= "Int" | "Unit" ;
BaseTypeDouble. BaseType ::= "Float";
token Id (lower (letter | digit | '_')*) ;
comment "//" ;
comment "/*" "*/" ;