-
Notifications
You must be signed in to change notification settings - Fork 5
/
solidity-syntax.k
296 lines (224 loc) · 10.8 KB
/
solidity-syntax.k
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
module SOLIDITY-SYNTAX
import DOMAINS-SYNTAX
import DOMAINS
syntax SourceUnit ::= PragmaDirectives ContractDefinitions
syntax PragmaDirectives ::= List{PragmaDirective, ""}
syntax PragmaDirective ::= "pragma" Id "^" Int "." Int "." Int ";"
syntax ContractDefinitions ::= List{ContractDefinition, ""} [klabel(#contractDefs)]
syntax ContractDefinition ::= "contract" Id "{" ContractParts "}" [klabel(#contractDef)]
| "library" Id "{" ContractParts "}"
| "contract" Id "is" Identifiers "{" ContractParts "}"
syntax ContractParts ::= List{ContractPart, " "} [klabel(#contractParts)]
syntax ContractPart ::= StateVariableDeclaration
| FunctionDefinition
syntax TypeName ::= NonArrayType
| ArrayTypeName
syntax NonArrayType ::= ElementaryTypeName | UserDefinedTypeName
syntax UserDefinedTypeName ::= Id
syntax ElementaryTypeName ::= AddressType | AddressPayableType | "string" | "var" | "bool" | SolidityInt | SolidityUint
syntax AddressPayableType ::= "address payable" [klabel(#address-payable)]
syntax AddressType ::= "address" [klabel(#address)]
syntax ArrayTypeName ::= TypeName "[" Expression "]" [strict(2)]
| TypeName "[" "]"
syntax SolidityInt ::= "int"
| "int8"
| "int16"
| "int24"
| "int32"
| "int40"
| "int48"
| "int56"
| "int128"
| "int136"
| "int144"
| "int152"
| "int160"
| "int168"
| "int176"
| "int184"
| "int192"
| "int200"
| "int208"
| "int216"
| "int224"
| "int232"
| "int240"
| "int248"
| "int256"
syntax SolidityUint ::= "uint"
| "uint8"
| "uint16"
| "uint24"
| "uint32"
| "uint40"
| "uint48"
| "uint56"
| "uint64"
| "uint72"
| "uint80"
| "uint88"
| "uint96"
| "uint104"
| "uint112"
| "uint120"
| "uint128"
| "uint136"
| "uint144"
| "uint152"
| "uint160"
| "uint168"
| "uint176"
| "uint184"
| "uint192"
| "uint200"
| "uint208"
| "uint216"
| "uint224"
| "uint232"
| "uint240"
| "uint248"
| "uint256"
syntax StateVariableDeclaration ::= TypeName FunQuantifiers Id ";" [klabel(#stateVarDecl)]
| TypeName FunQuantifiers Id "=" Expression ";" [klabel(#stateVarDeclWithAssignment)]
syntax FunQuantifier ::= ModifierInvocation
| Specifier
syntax ModifierInvocation ::= Id
| FunctionCall
syntax Specifier ::= "public"
| "internal"
| "private"
| "constant"
| "pure"
| "view"
| "payable"
| "external"
syntax FunQuantifiers ::= List{FunQuantifier," "}
syntax FunctionDefinition ::= "function" IdentifierOrNone "(" FParameters ")" FunQuantifiers "returns" "(" FParameters ")" Block [prefer]
| "function" IdentifierOrNone "(" FParameters ")" FunQuantifiers "returns" "(" FParameters ")" ";" [prefer]
| "function" IdentifierOrNone "(" FParameters ")" FunQuantifiers Block
| "function" IdentifierOrNone "(" FParameters ")" FunQuantifiers ";"
| "constructor" "(" FParameters ")" FunQuantifiers Block
syntax IdentifierOrNone
::= Id
| "" [klabel(#none), onlyLabel]
syntax FParameter ::= VariableDeclaration
| TypeName
syntax FParameters ::= List{FParameter, ","} [klabel(#fParameters)]
syntax VariableDeclaration ::= TypeName StorageLocations Id [klabel(#varDeclaration)]
syntax StorageLocations ::= List{StorageLocation, " "}
syntax StorageLocation ::= "memory" | "storage"
syntax Block ::= "{" Statements "}" [klabel(#block)]
syntax Statements ::= List{Statement, ""} [klabel(#statements)]
syntax Statement ::= BlockStatement
| SimpleStatement ";" [strict,klabel(#simpleStmt)]
| Break
| Continue
| "#loop_mark"
syntax SimpleStatement ::= FunctionCall
| Assignment
| Value
| VariableDefinition
| Return
| NewExpression
| MemOperation
syntax BlockStatement ::= IfStatement
| WhileStatement
| Block
syntax FunctionCall ::= Id "(" FunctionCallArguments ")" [strict(2),klabel(#localFunctionCall)]
| MemberAccess "(" FunctionCallArguments ")" [strict(2),klabel(#externalFunctionCall)]
| "functionCall" "(" Expression ";" Id ";" ExpressionList ")" [strict(1,3)]
| "functionCall" "(" Id ";" ExpressionList ")" [strict(2)]
syntax FunctionCallArguments ::= ExpressionList
| "{" NameValueList "}" [strict]
syntax ExpressionList ::= List{Expression, ","} [strict]
syntax NameValue ::= Id ":" Expression [strict(2)]
syntax NameValueList ::= List{NameValue, ","} [strict]
syntax Assignment ::= Expression "=" Expression [strict(2), klabel(#assign)]
syntax VariableDefinition ::= "var" Id
| VariableDeclaration
| VariableDeclaration "=" Expression [strict(2)]
syntax KResult ::= Value | Values
syntax Value
::= ValueResult | #tupleExp(ExpressionList) | #arrayExp(Expression)
syntax Values
::= List{Value, ","}
syntax ExpressionList ::= Values
syntax ValueResult ::= Bool | Int | String
syntax Return ::= "return" Expression [strict]
| "return"
syntax Break ::= "break" ";"
syntax Continue ::= "continue" ";"
syntax NewExpression ::= "new" Id "(" ExpressionList ")"
syntax TupleExpression ::= "[" ExpressionList "]" [klabel(#bracketTuple),strict(1)]
// | "(" ExpressionList ")" [klabel(#parTuple),strict(1)]
syntax Expression ::= Id | Value
| NewExpression
| IndexAccess
| FunctionCall
| MemberAccess
| TupleExpression
> left:
Expression "*" Expression [klabel(#multexp),strict,left]
| Expression "/" Expression [klabel(#divtexp),strict,left]
> left:
Expression "+" Expression [klabel(#addexp),strict,left]
| Expression "-" Expression [klabel(#subexp),strict,left]
> left:
Expression "<" Expression [klabel(#less),seqstrict,left]
| Expression "<=" Expression [klabel(#leq),seqstrict,left]
| Expression ">" Expression [klabel(#great),seqstrict,left]
| Expression ">=" Expression [klabel(#geq),seqstrict,left]
> left:
Expression "&&" Expression [klabel(#and),seqstrict,left]
| Expression "||" Expression [klabel(#or),seqstrict,left]
syntax IfStatement ::= "if" "(" Expression ")" Statement "else" Statement [strict(1)]
| "if" "(" Expression ")" Statement [strict(1)]
syntax WhileStatement ::= "while" "(" Expression ")" Statement
syntax Identifiers ::= List{Id, ","} [klabel(#identifiers)]
syntax MemberAccess ::= Expression "." Id [klabel(#memberAccess), strict(1)]
syntax IndexAccess ::= Expression "[" Expression "]" [strict(2), klabel(#indexAccess)]
| Expression "[" "]"
syntax AccountId
::= Id | "#Testing-Engine#"
syntax ContractInstanceSig
::= #account(Int,AccountId)
syntax ValueResult
::= "#undef_Value"
| "#end_Exp"
syntax VarInfo
::= #varInfo(Id, Expression, TypeName, MemFlag, Int) [strict(2)]
| #storedVar(Int, TypeName, MemFlag, Int)
syntax MemOperation
::= #read(Expression)
| #readAddress(Expression, MemFlag) [strict(1)]
| #write(Expression, Expression) [strict(2)]
| #writeAddress(Expression, Expression, MemFlag) [strict(1,2)]
| #allocate(Int, AccountId, VarInfo)
syntax MemFlag
::= "#mem"
| "#storage"
syntax OperandFlag
::= "#left"
| "#right"
syntax Exec
::= "#execute"
syntax SolidityItem ::= #exeStmt(Statement)
| AbnormalTerminationCode
| #allocateArray(MemOperation, Int, Int)
| #readArray(Expression, IndexAccess)
| #writeArray(Expression, IndexAccess, Expression)
| #assignArray(Id, ExpressionList, Expression, Expression, TypeName) [strict(3,4)]
| #copyArray(Int, MemFlag, Int, MemFlag, Int, Int)
| #processArrayExp(Expression, Value, List)
| #processArray(Expression, Expression, List, List)
| #processArrayIndex(Expression, Expression, OperandFlag, Expression, List, List) [strict(4)]
| #assignArrayPartial(Id, ExpressionList, TypeName, Int, List, Int)
| #copyArrayArrayPartial(Id, Id, TypeName, TypeName, Int, List, Int, List, Int, Int)
syntax AbnormalTerminationCode ::= "#continue#" | "#break#" | "#return#" | "#transfer-failed#"
syntax Expression ::= #getAddress(Int, Expression, Expression, Int, List, Expression) [strict(3)]
| #recordIndexLength(Int, Expression, Int, TypeName, Int, List)
| #getIndexAddress(Int, Expression, Int, TypeName, Int)
| #getRelativeAddr(Int, Expression, Int) [strict(2)]
| #tupleExp(ExpressionList) [strict]
| MemOperation
endmodule