2015-09-08 14:48:33 +00:00
|
|
|
ContractDefinition = ( 'contract' | 'library' ) Identifier
|
2015-01-19 20:05:47 +00:00
|
|
|
( 'is' InheritanceSpecifier (',' InheritanceSpecifier )* )?
|
|
|
|
'{' ContractPart* '}'
|
2016-07-20 13:59:00 +00:00
|
|
|
ContractPart = StateVariableDeclaration | StructDefinition | ModifierDefinition | FunctionDefinition | EventDefinition | EnumDefinition
|
2014-10-07 16:25:04 +00:00
|
|
|
|
2015-01-19 20:05:47 +00:00
|
|
|
InheritanceSpecifier = Identifier ( '(' Expression ( ',' Expression )* ')' )?
|
2014-10-07 16:25:04 +00:00
|
|
|
StructDefinition = 'struct' Identifier '{'
|
2016-07-20 00:18:09 +00:00
|
|
|
( VariableDeclaration ';' (VariableDeclaration ';')* )? '}'
|
2016-07-18 22:49:00 +00:00
|
|
|
StateVariableDeclaration = TypeName ( 'public' | 'internal' | 'private' )? Identifier ';'
|
2015-01-22 00:02:38 +00:00
|
|
|
ModifierDefinition = 'modifier' Identifier ParameterList? Block
|
2015-02-02 16:24:09 +00:00
|
|
|
FunctionDefinition = 'function' Identifier ParameterList
|
2016-07-18 22:49:00 +00:00
|
|
|
( Identifier | 'constant' | 'external' | 'public' | 'internal' | 'private' )*
|
2016-07-20 00:26:33 +00:00
|
|
|
( 'returns' (ParameterList | TypeParameterList) )? Block
|
2015-02-13 21:56:46 +00:00
|
|
|
|
2016-07-20 13:59:00 +00:00
|
|
|
EventDefinition = 'event' Identifier (ParameterList | TypeParameterList) ';'
|
|
|
|
|
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
|
|
|
|
|
|
|
TypeParameterList = '(' ( TypeName (',' TypeName)* )? ')'
|
2014-10-08 18:53:50 +00:00
|
|
|
ParameterList = '(' ( VariableDeclaration (',' VariableDeclaration)* )? ')'
|
2014-10-07 16:25:04 +00:00
|
|
|
// semantic restriction: mappings and structs (recursively) containing mappings
|
|
|
|
// are not allowed in argument lists
|
|
|
|
VariableDeclaration = TypeName Identifier
|
2015-02-21 17:25:08 +00:00
|
|
|
TypeName = ElementaryTypeName | Identifier | Mapping | ArrayTypeName
|
2014-10-08 18:53:50 +00:00
|
|
|
Mapping = 'mapping' '(' ElementaryTypeName '=>' TypeName ')'
|
2016-07-19 15:27:53 +00:00
|
|
|
ArrayTypeName = TypeName '[' Expression? ']'
|
2014-10-07 16:25:04 +00:00
|
|
|
|
|
|
|
Block = '{' Statement* '}'
|
2016-07-19 15:27:53 +00:00
|
|
|
Statement = IfStatement | WhileStatement | ForStatement | Block |
|
2016-07-18 23:26:39 +00:00
|
|
|
( Continue | Break | Return | Throw | VariableDefinition | ExpressionStatement ) ';'
|
2014-10-07 16:25:04 +00:00
|
|
|
|
2014-12-16 13:46:17 +00:00
|
|
|
ExpressionStatement = Expression
|
2014-10-07 16:25:04 +00:00
|
|
|
IfStatement = 'if' '(' Expression ')' Statement ( 'else' Statement )?
|
|
|
|
WhileStatement = 'while' '(' Expression ')' Statement
|
2016-07-20 00:18:09 +00:00
|
|
|
VardefOrExprStmt = VariableDefinition | ExpressionStatement
|
2014-12-16 13:46:17 +00:00
|
|
|
ForStatement = 'for' '(' (VardefOrExprStmt)? ';' (Expression)? ';' (ExpressionStatement)? ')' Statement
|
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'
|
2016-07-18 23:26:39 +00:00
|
|
|
VariableDefinition = VariableDeclaration ( '=' Expression )?
|
2014-10-07 16:25:04 +00:00
|
|
|
|
2014-12-12 15:49:26 +00:00
|
|
|
Expression = Assignment | UnaryOperation | BinaryOperation | FunctionCall | NewExpression | IndexAccess |
|
2016-07-14 21:48:29 +00:00
|
|
|
MemberAccess | PrimaryExpression
|
2014-10-09 13:57:49 +00:00
|
|
|
// The expression syntax is actually much more complicated
|
2014-10-07 16:25:04 +00:00
|
|
|
Assignment = Expression (AssignmentOp Expression)
|
2016-07-19 15:27:53 +00:00
|
|
|
AssignmentOp = '|=' | '^=' | '&=' | '<<=' | '>>=' | '+=' | '-=' | '*=' | '/=' | '%='
|
2016-07-14 21:41:32 +00:00
|
|
|
UnaryOperation = '!' | '~' | '++' | '--' | 'delete'
|
2016-07-19 15:27:53 +00:00
|
|
|
BinaryOperation = '|' | '^' | '&' | '<<' | '>>' | '+' | '-' | '*' | '/' | '%'
|
|
|
|
| '||' | '&&' | '**' | '==' | '!=' | '<' | '>' | '<=' | '>='
|
2016-07-14 21:41:32 +00:00
|
|
|
|
2016-07-18 23:26:39 +00:00
|
|
|
FunctionCall = Identifier '(' Expression? ( ',' Expression )* ')'
|
2015-01-13 17:12:19 +00:00
|
|
|
NewExpression = 'new' Identifier
|
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
|
|
|
PrimaryExpression = Identifier | BooleanLiteral | NumberLiteral | StringLiteral | ElementaryTypeName | '(' Expression ')'
|
|
|
|
|
|
|
|
BooleanLiteral = 'true' | 'false'
|
2016-07-20 00:42:02 +00:00
|
|
|
NumberLiteral = '0x'? [0-9]+
|
2016-07-20 00:18:09 +00:00
|
|
|
StringLiteral = '"' [a-zA-Z_0-9]* '"'
|
|
|
|
Identifier = [a-zA-Z_] [a-zA-Z_0-9]*
|
2016-07-19 16:59:34 +00:00
|
|
|
|
|
|
|
ElementaryTypeName = 'address' | 'bool' | 'string'
|
2016-07-19 23:33:08 +00:00
|
|
|
| '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' | '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' | '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'
|
|
|
|
| 'fixed' | 'fixed0x8' | 'fixed0x16' | 'fixed0x24' | 'fixed0x32' | 'fixed0x40' | 'fixed0x48' | 'fixed0x56' | 'fixed0x64' | 'fixed0x72' | 'fixed0x80' | 'fixed0x88' | 'fixed0x96' | 'fixed0x104' | 'fixed0x112' | 'fixed0x120' | 'fixed0x128' | 'fixed0x136' | 'fixed0x144' | 'fixed0x152' | 'fixed0x160' | 'fixed0x168' | 'fixed0x176' | 'fixed0x184' | 'fixed0x192' | 'fixed0x200' | 'fixed0x208' | 'fixed0x216' | 'fixed0x224' | 'fixed0x232' | 'fixed0x240' | 'fixed0x248' | 'fixed0x256'
|
|
|
|
| 'ufixed' | 'ufixed0x8' | 'ufixed0x16' | 'ufixed0x24' | 'ufixed0x32' | 'ufixed0x40' | 'ufixed0x48' | 'ufixed0x56' | 'ufixed0x64' | 'ufixed0x72' | 'ufixed0x80' | 'ufixed0x88' | 'ufixed0x96' | 'ufixed0x104' | 'ufixed0x112' | 'ufixed0x120' | 'ufixed0x128' | 'ufixed0x136' | 'ufixed0x144' | 'ufixed0x152' | 'ufixed0x160' | 'ufixed0x168' | 'ufixed0x176' | 'ufixed0x184' | 'ufixed0x192' | 'ufixed0x200' | 'ufixed0x208' | 'ufixed0x216' | 'ufixed0x224' | 'ufixed0x232' | 'ufixed0x240' | 'ufixed0x248' | 'ufixed0x256'
|