2016-08-19 17:57:21 +00:00
|
|
|
|
SourceUnit = (PragmaDirective | ImportDirective | ContractDefinition)*
|
2016-07-27 14:01:30 +00:00
|
|
|
|
|
2016-08-19 17:57:21 +00:00
|
|
|
|
// Pragma actually parses anything up to the trailing ';' to be fully forward-compatible.
|
2016-11-18 03:15:24 +00:00
|
|
|
|
PragmaDirective = 'pragma' Identifier ([^;]+) ';'
|
2016-07-20 17:17:03 +00:00
|
|
|
|
|
2016-08-01 20:33:05 +00:00
|
|
|
|
ImportDirective = 'import' StringLiteral ('as' Identifier)? ';'
|
|
|
|
|
| 'import' ('*' | Identifier) ('as' Identifier)? 'from' StringLiteral ';'
|
|
|
|
|
| 'import' '{' Identifier ('as' Identifier)? ( ',' Identifier ('as' Identifier)? )* '}' 'from' StringLiteral ';'
|
2016-07-20 14:14:23 +00:00
|
|
|
|
|
2017-06-14 23:41:00 +00:00
|
|
|
|
ContractDefinition = ( 'contract' | 'library' | 'interface' ) Identifier
|
2016-08-19 17:57:21 +00:00
|
|
|
|
( 'is' InheritanceSpecifier (',' InheritanceSpecifier )* )?
|
|
|
|
|
'{' ContractPart* '}'
|
|
|
|
|
|
2016-07-27 14:03:40 +00:00
|
|
|
|
ContractPart = StateVariableDeclaration | UsingForDeclaration
|
2016-07-20 17:31:05 +00:00
|
|
|
|
| StructDefinition | ModifierDefinition | FunctionDefinition | EventDefinition | EnumDefinition
|
2014-10-07 16:25:04 +00:00
|
|
|
|
|
2016-12-28 02:08:57 +00:00
|
|
|
|
InheritanceSpecifier = UserDefinedTypeName ( '(' Expression ( ',' Expression )* ')' )?
|
2016-07-20 17:31:05 +00:00
|
|
|
|
|
2018-04-23 09:04:43 +00:00
|
|
|
|
StateVariableDeclaration = TypeName ( 'public' | 'internal' | 'private' | 'constant' )* Identifier ('=' Expression)? ';'
|
2016-07-27 14:03:40 +00:00
|
|
|
|
UsingForDeclaration = 'using' Identifier 'for' ('*' | TypeName) ';'
|
2014-10-07 16:25:04 +00:00
|
|
|
|
StructDefinition = 'struct' Identifier '{'
|
2018-03-27 13:38:28 +00:00
|
|
|
|
( VariableDeclaration ';' (VariableDeclaration ';')* ) '}'
|
2017-06-14 22:15:35 +00:00
|
|
|
|
|
2015-01-22 00:02:38 +00:00
|
|
|
|
ModifierDefinition = 'modifier' Identifier ParameterList? Block
|
2017-06-14 22:15:35 +00:00
|
|
|
|
ModifierInvocation = Identifier ( '(' ExpressionList? ')' )?
|
|
|
|
|
|
2016-08-09 09:53:38 +00:00
|
|
|
|
FunctionDefinition = 'function' Identifier? ParameterList
|
2017-08-16 20:19:09 +00:00
|
|
|
|
( ModifierInvocation | StateMutability | 'external' | 'public' | 'internal' | 'private' )*
|
2016-12-27 01:57:00 +00:00
|
|
|
|
( 'returns' ParameterList )? ( ';' | Block )
|
2017-12-24 07:43:53 +00:00
|
|
|
|
EventDefinition = 'event' Identifier EventParameterList 'anonymous'? ';'
|
2016-07-20 13:59:00 +00:00
|
|
|
|
|
2015-02-13 21:56:46 +00:00
|
|
|
|
EnumValue = Identifier
|
2016-07-18 23:03:41 +00:00
|
|
|
|
EnumDefinition = 'enum' Identifier '{' EnumValue? (',' EnumValue)* '}'
|
2016-07-20 00:26:33 +00:00
|
|
|
|
|
2017-12-24 07:43:53 +00:00
|
|
|
|
ParameterList = '(' ( Parameter (',' Parameter)* )? ')'
|
|
|
|
|
Parameter = TypeName StorageLocation? Identifier?
|
|
|
|
|
|
|
|
|
|
EventParameterList = '(' ( EventParameter (',' EventParameter )* )? ')'
|
|
|
|
|
EventParameter = TypeName 'indexed'? Identifier?
|
|
|
|
|
|
|
|
|
|
FunctionTypeParameterList = '(' ( FunctionTypeParameter (',' FunctionTypeParameter )* )? ')'
|
|
|
|
|
FunctionTypeParameter = TypeName StorageLocation?
|
2016-07-30 13:34:46 +00:00
|
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
|
// semantic restriction: mappings and structs (recursively) containing mappings
|
|
|
|
|
// are not allowed in argument lists
|
2017-01-11 03:51:28 +00:00
|
|
|
|
VariableDeclaration = TypeName StorageLocation? Identifier
|
2016-12-28 02:08:57 +00:00
|
|
|
|
|
|
|
|
|
TypeName = ElementaryTypeName
|
2017-01-11 03:51:28 +00:00
|
|
|
|
| UserDefinedTypeName
|
2016-12-28 02:08:57 +00:00
|
|
|
|
| Mapping
|
|
|
|
|
| ArrayTypeName
|
|
|
|
|
| FunctionTypeName
|
|
|
|
|
|
|
|
|
|
UserDefinedTypeName = Identifier ( '.' Identifier )*
|
|
|
|
|
|
2014-10-08 18:53:50 +00:00
|
|
|
|
Mapping = 'mapping' '(' ElementaryTypeName '=>' TypeName ')'
|
2017-01-11 03:51:28 +00:00
|
|
|
|
ArrayTypeName = TypeName '[' Expression? ']'
|
2017-12-24 07:43:53 +00:00
|
|
|
|
FunctionTypeName = 'function' FunctionTypeParameterList ( 'internal' | 'external' | StateMutability )*
|
|
|
|
|
( 'returns' FunctionTypeParameterList )?
|
2018-05-23 04:31:20 +00:00
|
|
|
|
StorageLocation = 'memory' | 'storage' | 'calldata'
|
2018-05-08 11:08:22 +00:00
|
|
|
|
StateMutability = 'pure' | 'view' | 'payable'
|
2014-10-07 16:25:04 +00:00
|
|
|
|
|
|
|
|
|
Block = '{' Statement* '}'
|
2016-12-01 15:24:43 +00:00
|
|
|
|
Statement = IfStatement | WhileStatement | ForStatement | Block | InlineAssemblyStatement |
|
2016-11-11 08:33:19 +00:00
|
|
|
|
( DoWhileStatement | PlaceholderStatement | Continue | Break | Return |
|
2018-02-16 15:55:21 +00:00
|
|
|
|
Throw | EmitStatement | SimpleStatement ) ';'
|
2014-10-07 16:25:04 +00:00
|
|
|
|
|
2016-09-06 03:18:43 +00:00
|
|
|
|
ExpressionStatement = Expression
|
2014-10-07 16:25:04 +00:00
|
|
|
|
IfStatement = 'if' '(' Expression ')' Statement ( 'else' Statement )?
|
|
|
|
|
WhileStatement = 'while' '(' Expression ')' Statement
|
2016-07-25 15:48:49 +00:00
|
|
|
|
PlaceholderStatement = '_'
|
2016-09-06 03:18:43 +00:00
|
|
|
|
SimpleStatement = VariableDefinition | ExpressionStatement
|
2016-07-27 14:42:33 +00:00
|
|
|
|
ForStatement = 'for' '(' (SimpleStatement)? ';' (Expression)? ';' (ExpressionStatement)? ')' Statement
|
2017-06-14 23:43:19 +00:00
|
|
|
|
InlineAssemblyStatement = 'assembly' StringLiteral? InlineAssemblyBlock
|
2016-11-11 08:33:19 +00:00
|
|
|
|
DoWhileStatement = 'do' Statement 'while' '(' Expression ')'
|
2016-07-18 23:26:39 +00:00
|
|
|
|
Continue = 'continue'
|
|
|
|
|
Break = 'break'
|
|
|
|
|
Return = 'return' Expression?
|
2016-07-19 15:27:53 +00:00
|
|
|
|
Throw = 'throw'
|
2018-02-16 15:55:21 +00:00
|
|
|
|
EmitStatement = 'emit' FunctionCall
|
2018-06-11 12:06:22 +00:00
|
|
|
|
VariableDefinition = (VariableDeclaration | '(' VariableDeclaration? (',' VariableDeclaration? )* ')' ) ( '=' Expression )?
|
2014-10-07 16:25:04 +00:00
|
|
|
|
|
2016-07-23 14:15:01 +00:00
|
|
|
|
// Precedence by order (see github.com/ethereum/solidity/pull/732)
|
2017-06-14 22:15:35 +00:00
|
|
|
|
Expression
|
|
|
|
|
= Expression ('++' | '--')
|
|
|
|
|
| NewExpression
|
|
|
|
|
| IndexAccess
|
2017-06-15 01:59:58 +00:00
|
|
|
|
| MemberAccess
|
|
|
|
|
| FunctionCall
|
|
|
|
|
| '(' Expression ')'
|
2016-08-10 20:25:17 +00:00
|
|
|
|
| ('!' | '~' | 'delete' | '++' | '--' | '+' | '-') Expression
|
2016-07-23 14:15:01 +00:00
|
|
|
|
| Expression '**' Expression
|
|
|
|
|
| Expression ('*' | '/' | '%') Expression
|
|
|
|
|
| Expression ('+' | '-') Expression
|
2016-12-28 15:53:40 +00:00
|
|
|
|
| Expression ('<<' | '>>') Expression
|
2016-07-23 14:15:01 +00:00
|
|
|
|
| Expression '&' Expression
|
|
|
|
|
| Expression '^' Expression
|
|
|
|
|
| Expression '|' Expression
|
|
|
|
|
| Expression ('<' | '>' | '<=' | '>=') Expression
|
|
|
|
|
| Expression ('==' | '!=') Expression
|
|
|
|
|
| Expression '&&' Expression
|
|
|
|
|
| Expression '||' Expression
|
|
|
|
|
| Expression '?' Expression ':' Expression
|
2016-07-27 14:42:33 +00:00
|
|
|
|
| Expression ('=' | '|=' | '^=' | '&=' | '<<=' | '>>=' | '+=' | '-=' | '*=' | '/=' | '%=') Expression
|
2016-07-22 23:45:10 +00:00
|
|
|
|
| PrimaryExpression
|
|
|
|
|
|
2017-06-15 01:59:58 +00:00
|
|
|
|
PrimaryExpression = BooleanLiteral
|
2016-12-27 19:10:09 +00:00
|
|
|
|
| NumberLiteral
|
|
|
|
|
| HexLiteral
|
|
|
|
|
| StringLiteral
|
2017-06-19 20:16:45 +00:00
|
|
|
|
| TupleExpression
|
2017-06-15 01:59:58 +00:00
|
|
|
|
| Identifier
|
2016-12-27 19:10:09 +00:00
|
|
|
|
| ElementaryTypeNameExpression
|
2016-07-14 21:41:32 +00:00
|
|
|
|
|
2017-01-11 04:33:17 +00:00
|
|
|
|
ExpressionList = Expression ( ',' Expression )*
|
|
|
|
|
NameValueList = Identifier ':' Expression ( ',' Identifier ':' Expression )*
|
|
|
|
|
|
2017-06-14 22:15:35 +00:00
|
|
|
|
FunctionCall = Expression '(' FunctionCallArguments ')'
|
2017-01-11 04:33:17 +00:00
|
|
|
|
FunctionCallArguments = '{' NameValueList? '}'
|
|
|
|
|
| ExpressionList?
|
|
|
|
|
|
2017-01-11 04:35:29 +00:00
|
|
|
|
NewExpression = 'new' TypeName
|
2014-10-07 16:25:04 +00:00
|
|
|
|
MemberAccess = Expression '.' Identifier
|
2016-07-19 16:59:34 +00:00
|
|
|
|
IndexAccess = Expression '[' Expression? ']'
|
2016-07-20 00:18:09 +00:00
|
|
|
|
|
|
|
|
|
BooleanLiteral = 'true' | 'false'
|
2016-12-24 16:10:51 +00:00
|
|
|
|
NumberLiteral = ( HexNumber | DecimalNumber ) (' ' NumberUnit)?
|
2016-07-20 15:07:26 +00:00
|
|
|
|
NumberUnit = 'wei' | 'szabo' | 'finney' | 'ether'
|
2016-07-20 14:49:14 +00:00
|
|
|
|
| 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'years'
|
2016-10-10 21:08:44 +00:00
|
|
|
|
HexLiteral = 'hex' ('"' ([0-9a-fA-F]{2})* '"' | '\'' ([0-9a-fA-F]{2})* '\'')
|
2016-07-23 00:35:20 +00:00
|
|
|
|
StringLiteral = '"' ([^"\r\n\\] | '\\' .)* '"'
|
2017-01-20 18:29:43 +00:00
|
|
|
|
Identifier = [a-zA-Z_$] [a-zA-Z_$0-9]*
|
2016-07-20 14:49:14 +00:00
|
|
|
|
|
2018-09-02 15:57:21 +00:00
|
|
|
|
HexNumber = '0' [xX] [0-9a-fA-F]+
|
2017-11-05 14:40:57 +00:00
|
|
|
|
DecimalNumber = [0-9]+ ( '.' [0-9]* )? ( [eE] [0-9]+ )?
|
2016-12-24 16:10:51 +00:00
|
|
|
|
|
2017-11-14 19:30:41 +00:00
|
|
|
|
TupleExpression = '(' ( Expression? ( ',' Expression? )* )? ')'
|
|
|
|
|
| '[' ( Expression ( ',' Expression )* )? ']'
|
2017-06-19 20:16:45 +00:00
|
|
|
|
|
2016-12-27 19:10:09 +00:00
|
|
|
|
ElementaryTypeNameExpression = ElementaryTypeName
|
|
|
|
|
|
2018-06-11 12:06:22 +00:00
|
|
|
|
ElementaryTypeName = 'address' | 'bool' | 'string' | Int | Uint | Byte | Fixed | Ufixed
|
2016-08-02 15:18:59 +00:00
|
|
|
|
|
|
|
|
|
Int = 'int' | 'int8' | 'int16' | 'int24' | 'int32' | 'int40' | 'int48' | 'int56' | 'int64' | 'int72' | 'int80' | 'int88' | 'int96' | 'int104' | 'int112' | 'int120' | 'int128' | 'int136' | 'int144' | 'int152' | 'int160' | 'int168' | 'int176' | 'int184' | 'int192' | 'int200' | 'int208' | 'int216' | 'int224' | 'int232' | 'int240' | 'int248' | 'int256'
|
|
|
|
|
|
|
|
|
|
Uint = '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'
|
|
|
|
|
|
|
|
|
|
Byte = 'byte' | 'bytes' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | 'bytes17' | 'bytes18' | 'bytes19' | 'bytes20' | 'bytes21' | 'bytes22' | 'bytes23' | 'bytes24' | 'bytes25' | 'bytes26' | 'bytes27' | 'bytes28' | 'bytes29' | 'bytes30' | 'bytes31' | 'bytes32'
|
|
|
|
|
|
2017-11-05 14:40:57 +00:00
|
|
|
|
Fixed = 'fixed' | ( 'fixed' [0-9]+ 'x' [0-9]+ )
|
2016-08-02 15:18:59 +00:00
|
|
|
|
|
2017-11-05 14:40:57 +00:00
|
|
|
|
Ufixed = 'ufixed' | ( 'ufixed' [0-9]+ 'x' [0-9]+ )
|
2016-12-01 15:24:43 +00:00
|
|
|
|
|
|
|
|
|
InlineAssemblyBlock = '{' AssemblyItem* '}'
|
|
|
|
|
|
2018-07-24 23:08:42 +00:00
|
|
|
|
AssemblyItem = Identifier | FunctionalAssemblyExpression | InlineAssemblyBlock | AssemblyVariableDeclaration | AssemblyAssignment | AssemblyLabel | NumberLiteral | StringLiteral | HexLiteral
|
2018-07-24 23:08:08 +00:00
|
|
|
|
AssemblyExpression = Identifier | FunctionalAssemblyExpression | NumberLiteral | StringLiteral | HexLiteral
|
2018-07-24 23:08:42 +00:00
|
|
|
|
AssemblyVariableDeclaration = 'let' Identifier ':=' AssemblyExpression
|
2018-07-24 23:08:08 +00:00
|
|
|
|
AssemblyAssignment = ( Identifier ':=' AssemblyExpression ) | ( '=:' Identifier )
|
2017-06-14 23:40:01 +00:00
|
|
|
|
AssemblyLabel = Identifier ':'
|
2016-12-01 15:24:43 +00:00
|
|
|
|
FunctionalAssemblyExpression = Identifier '(' AssemblyItem? ( ',' AssemblyItem )* ')'
|