-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavalette.cf
202 lines (106 loc) · 3.94 KB
/
Javalette.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
-- programs ------------------------------------------------
entrypoints Prog ;
Program. Prog ::= [TopDef] ;
Struct. TopDef ::= "struct" Ident SBlk ";" ;
TypeDef. TopDef ::= "typedef" "struct" Ident "*" Ident ";" ;
TypeDefWS. TopDef ::= "typedef" "struct" Ident SBlk "*" Ident ";" ;
Enum. TopDef ::= "enum" Ident "{"[EVal]"}" ";" ;
Class. TopDef ::= "class" Ident CBlk ;
ClassWE. TopDef ::= "class" Ident "extends" Ident CBlk ;
GFuncDef. TopDef ::= FnDef ;
FuncDef. FnDef ::= Type Ident "(" [Arg] ")" Blk ;
EnumValue. EVal ::= Ident;
separator EVal "," ;
Argument. Arg ::= Type Ident;
separator Arg "," ;
separator nonempty TopDef "" ;
-- Type ----------------------------------------------
Int. BType ::= "int" ;
Doub. BType ::= "double" ;
Bool. BType ::= "boolean" ;
Void. BType ::= "void" ;
ObjT. OType ::= Ident ;
Array. AType ::= Type BracketsOpt ;
BaseType. Type ::= BType ;
ObjType. Type ::= OType ;
ArrType. Type ::= AType ;
BracketsEmpty. BracketsOpt ::= "[]" ;
separator nonempty BracketsOpt "";
separator Type "," ;
-- struct and class define ---------------------------------
SBlock. SBlk ::= "{" [Memdef] "}" ;
CBlock. CBlk ::= "{" [CMemdef] "}" ;
MemberItem. MemItem ::= Ident ;
separator MemItem "," ;
MemberDef. Memdef ::= Type [MemItem] ";" ;
separator Memdef "" ;
CVarDef. CMemdef ::= Memdef ;
CFuncDef. CMemdef ::= FnDef ;
separator CMemdef "" ;
-- function statements ----------------------------------------------
Block. Blk ::= "{" [Stmt] "}" ;
separator Stmt "" ;
Empty. Stmt ::= ";" ;
BStmt. Stmt ::= Blk ;
-- define variable -----------------------------------------
Decl. Stmt ::= Type [Item] ";" ;
NoInit. Item ::= Ident ;
Init. Item ::= Ident "=" Expr ;
SExp. Stmt ::= Expr ";" ;
separator nonempty Item "," ;
-- Access a variable ---------------------------------------
Ass. Stmt ::= Expr "=" Expr ";" ;
-- Return --------------------------------------------------
Ret. Stmt ::= "return" Expr ";" ;
VRet. Stmt ::= "return" ";" ;
-- Condition and loop --------------------------------------
Cond. Stmt ::= "if" "(" Expr ")" Stmt ;
CondElse. Stmt ::= "if" "(" Expr ")" Stmt "else" Stmt ;
While. Stmt ::= "while" "(" Expr ")" Stmt ;
ForLoop. Stmt ::= "for" "(" Type Ident ":" Expr ")" Stmt ;
-- Expr ----------------------------------------------------
Ecast. Expr6 ::= "(" Type ")" Expr6 ;
ELitNull. Expr6 ::= "null";
ELitInt. Expr6 ::= Integer ;
ELitDoub. Expr6 ::= Double ;
ELitTrue. Expr6 ::= "true" ;
ELitFalse. Expr6 ::= "false" ;
EString. Expr6 ::= String ;
EVar. Expr6 ::= Ident ;
EApp. Expr6 ::= Ident "(" [Expr] ")" ;
ENewObj. Expr6 ::= "new" OType;
EArrow. Expr6 ::= Expr6 "->" Ident ;
Epropety. Expr6 ::= Expr6 "." Ident ;
EFunc. Expr6 ::= Expr6 "." Ident "(" [Expr] ")" ;
Dim. DimExpr ::= "[" Expr "]" ;
terminator nonempty DimExpr "" ;
ENewBArr. Expr6 ::= "new" BType [DimExpr] ;
ENewOArr. Expr6 ::= "new" OType [DimExpr] ;
EAcc. Expr6 ::= Expr6 [DimExpr] ;
EInc. Expr6 ::= Expr6 "++" ;
EDecr. Expr6 ::= Expr6 "--" ;
ENeg. Expr5 ::= "-" Expr6 ;
ENot. Expr5 ::= "!" Expr5 ;
EMul. Expr4 ::= Expr4 MulOp Expr5 ;
EAdd. Expr3 ::= Expr3 AddOp Expr4 ;
ERel. Expr2 ::= Expr2 RelOp Expr3 ;
EAnd. Expr3 ::= Expr2 "&&" Expr1 ;
EOr. Expr ::= Expr1 "||" Expr;
coercions Expr 6 ;
separator Expr "," ;
-- operators -----------------------------------------------
Plus. AddOp ::= "+" ;
Minus. AddOp ::= "-" ;
Times. MulOp ::= "*" ;
Div. MulOp ::= "/" ;
Mod. MulOp ::= "%" ;
LTH. RelOp ::= "<" ;
LE. RelOp ::= "<=" ;
GTH. RelOp ::= ">" ;
GE. RelOp ::= ">=" ;
EQU. RelOp ::= "==" ;
NE. RelOp ::= "!=" ;
-- comments ------------------------------------------------
comment "#" ;
comment "//" ;
comment "/*" "*/" ;