-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grammar.cf
122 lines (98 loc) · 4.18 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
WFile. WFile ::= [Import] [WLibraryElement] WProgram;
separator Import "";
separator WLibraryElement "";
Import. Import ::= "import - TODO";
WTopLevelClass. WLibraryElement ::= WClassDeclaration;
WTopLevelObject. WLibraryElement ::= WObjectDeclaration;
WProgram. WProgram ::= "program" Ident "{" [WStatement] "}";
terminator WStatement "";
WClassDeclaration. WClassDeclaration ::=
"class" Ident WSuperclassDeclaration "{"
[WVariableDeclaration]
[WMethodDeclaration]
"}";
separator WVariableDeclaration "";
separator WMethodDeclaration "";
WSuperclass. WSuperclassDeclaration ::= "inherits" Ident;
WNoSuperclass. WSuperclassDeclaration ::= ;
WMethodDeclaration. WMethodDeclaration ::=
"method" WSelector "(" [Ident] ")" MethodBody;
separator Ident ",";
WObjectDeclaration. WObjectDeclaration ::=
"object" Ident WSuperclassDeclaration "{"
[WVariableDeclaration]
[WMethodDeclaration]
"}";
WSelector. WSelector ::= Ident;
WAddOpSelector. WSelector ::= OpAdd;
WOrOpSelector. WSelector ::= OpOr;
WAndOpSelector. WSelector ::= OpAnd;
WMultOpSelector. WSelector ::= OpMult;
WEqOpSelector. WSelector ::= OpEq;
WCmpOpSelector. WSelector ::= OpCmp;
WPowerOpSelector. WSelector ::= OpPower;
WUnaryOpSelector. WSelector ::= OpUnary;
WPostfixOpSelector. WSelector ::= OpPostfix;
ImplementedByBlock. MethodBody ::= "{" [WStatement] "}";
ImplementedByExpression. MethodBody ::= "=" WExpression;
ImplementedNatively. MethodBody ::= "native";
TopLevelExpression. WStatement ::= WExpression;
VarDeclaration. WStatement ::= WVariableDeclaration;
WReturn. WStatement ::= "return" WExpression;
WThrow. WStatement ::= "throw" WExpression;
WAssignment. WStatement ::= Ident "=" WExpression;
WVariableDeclaration. WVariableDeclaration ::= WVariableType Ident WVariableValue;
Var. WVariableType ::= "var";
Const. WVariableType ::= "const";
WithInitialValue. WVariableValue ::= "=" WExpression;
NoIntialValue. WVariableValue ::= ;
SingleExpression. WBlockOrStatement ::= WStatement;
Block. WBlockOrStatement ::= "{" [WStatement] "}";
WTry. WExpression ::= "try" WBlockOrStatement [WCatch] WThenAlways;
separator WCatch "";
WCatch. WCatch ::= "catch" Ident ExceptionType WBlockOrStatement;
WThenAlwaysProvided. WThenAlways ::= "then" "always" WBlockOrStatement;
WNoThenAlways. WThenAlways ::= ;
ProvidedExceptionType. ExceptionType ::= ":" Ident;
DefaultExceptionType. ExceptionType ::= ;
rules OpOr ::= "||" | "or";
WOrExpression. WExpression1 ::= WExpression OpOr WExpression1;
rules OpAnd ::= "&&" | "and";
WAndExpression. WExpression1 ::= WExpression1 OpAnd WExpression2;
rules OpEq ::= "==" | "!=" | "===" | "!==";
WEqExpression. WExpression2 ::= WExpression2 OpEq WExpression3;
rules OpCmp ::= ">=" | "<=" | ">" | "<";
WCmpExpression. WExpression3 ::= WExpression3 OpCmp WExpression4;
rules OpAdd ::= "+" | "-";
WAddExpression. WExpression4 ::= WExpression4 OpAdd WExpression5;
rules OpMult ::= "*" | "/" | "%";
WMultExpression. WExpression5 ::= WExpression5 OpMult WExpression6;
rules OpPower ::= "**";
WPowerExpression. WExpression6 ::= WExpression7 OpPower WExpression6;
rules OpUnary ::= "not" | "!" | "-" | "+";
WUnaryExpression. WExpression7 ::= OpUnary WExpression8;
rules OpPostfix ::= "++" | "--";
WPostfixExpression. WExpression8 ::= WExpression9 OpPostfix;
WMessageSend. WExpression9 ::=
WExpression9 "." Ident "(" [WExpression] ")";
separator WExpression ",";
WClosureLiteral . WExpression10 ::= "{" WClosureParameters [WStatement] "}";
WNoParameters . WClosureParameters ::=;
WWithParameters . WClosureParameters ::= [Ident] "=>";
WIf . WExpression10 ::= "if" "(" WExpression ")" WBlockOrStatement WElse;
WNoElse . WElse ::= ;
WElse . WElse ::= "else" WBlockOrStatement;
WObjectLiteral. WExpression10 ::= WObjectDeclaration;
WNew. WExpression10 ::= "new" Ident "(" [WNewParameter] ")";
WNewParameter. WNewParameter ::= Ident "=" WExpression;
separator WNewParameter ",";
WNumberLiteral. WExpression10 ::= Integer;
WNullLiteral. WExpression10 ::= "null";
WLiteralTrue. WExpression10 ::= "true";
WLiteralFalse. WExpression10 ::= "false";
WSelf. WExpression10 ::= "self";
WStringLiteral. WExpression10 ::= String;
WVariable. WExpression10 ::= Ident;
comment "//" ;
comment "/*" "*/" ;
coercions WExpression 10;