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
|
|
|
|
|
2017-08-16 20:22:59 +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 '{'
|
2016-07-20 00:18:09 +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 )
|
2016-08-01 20:33:05 +00:00
|
|
|
|
EventDefinition = 'event' Identifier IndexedParameterList '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
|
|
|
|
|
2016-08-01 20:33:05 +00:00
|
|
|
|
IndexedParameterList = '(' ( TypeName 'indexed'? Identifier? (',' TypeName 'indexed'? Identifier?)* )? ')'
|
|
|
|
|
ParameterList = '(' ( TypeName Identifier? (',' TypeName Identifier?)* )? ')'
|
2016-11-08 10:48:28 +00:00
|
|
|
|
TypeNameList = '(' ( TypeName (',' TypeName )* )? ')'
|
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-08-16 20:19:09 +00:00
|
|
|
|
FunctionTypeName = 'function' TypeNameList ( 'internal' | 'external' | StateMutability )*
|
2016-11-08 10:48:28 +00:00
|
|
|
|
( 'returns' TypeNameList )?
|
2016-07-25 15:28:30 +00:00
|
|
|
|
StorageLocation = 'memory' | 'storage'
|
2017-08-16 20:19:09 +00:00
|
|
|
|
StateMutability = 'constant' | '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 |
|
2016-09-05 16:58:58 +00:00
|
|
|
|
Throw | 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'
|
2017-02-03 06:37:24 +00:00
|
|
|
|
VariableDefinition = ('var' IdentifierList | VariableDeclaration) ( '=' Expression )?
|
|
|
|
|
IdentifierList = '(' ( Identifier? ',' )* Identifier? ')'
|
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
|
|
|
|
|
2016-12-24 16:10:51 +00:00
|
|
|
|
HexNumber = '0x' [0-9a-fA-F]+
|
|
|
|
|
DecimalNumber = [0-9]+
|
|
|
|
|
|
2017-06-19 20:16:45 +00:00
|
|
|
|
TupleExpression = '(' ( Expression ( ',' Expression )* )? ')'
|
|
|
|
|
| '[' ( Expression ( ',' Expression )* )? ']'
|
|
|
|
|
|
2016-12-27 19:10:09 +00:00
|
|
|
|
ElementaryTypeNameExpression = ElementaryTypeName
|
|
|
|
|
|
2016-07-27 14:42:33 +00:00
|
|
|
|
ElementaryTypeName = 'address' | 'bool' | 'string' | 'var'
|
2016-08-02 15:18:59 +00:00
|
|
|
|
| Int | Uint | Byte | Fixed | Ufixed
|
|
|
|
|
|
|
|
|
|
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-07-27 13:36:56 +00:00
|
|
|
|
Fixed = 'fixed' | ( 'fixed' DecimalNumber 'x' DecimalNumber )
|
2016-08-02 15:18:59 +00:00
|
|
|
|
|
2017-07-27 13:36:56 +00:00
|
|
|
|
Uixed = 'ufixed' | ( 'ufixed' DecimalNumber 'x' DecimalNumber )
|
2016-12-01 15:24:43 +00:00
|
|
|
|
|
|
|
|
|
InlineAssemblyBlock = '{' AssemblyItem* '}'
|
|
|
|
|
|
2017-06-14 23:40:01 +00:00
|
|
|
|
AssemblyItem = Identifier | FunctionalAssemblyExpression | InlineAssemblyBlock | AssemblyLocalBinding | AssemblyAssignment | AssemblyLabel | NumberLiteral | StringLiteral | HexLiteral
|
2016-12-01 15:24:43 +00:00
|
|
|
|
AssemblyLocalBinding = 'let' Identifier ':=' FunctionalAssemblyExpression
|
2017-06-14 23:39:46 +00:00
|
|
|
|
AssemblyAssignment = ( Identifier ':=' FunctionalAssemblyExpression ) | ( '=:' Identifier )
|
2017-06-14 23:40:01 +00:00
|
|
|
|
AssemblyLabel = Identifier ':'
|
2016-12-01 15:24:43 +00:00
|
|
|
|
FunctionalAssemblyExpression = Identifier '(' AssemblyItem? ( ',' AssemblyItem )* ')'
|