2015-09-08 14:48:33 +00:00
|
|
|
ContractDefinition = ( 'contract' | 'library' ) Identifier
|
2015-01-19 20:05:47 +00:00
|
|
|
( 'is' InheritanceSpecifier (',' InheritanceSpecifier )* )?
|
|
|
|
'{' ContractPart* '}'
|
2015-02-13 21:56:46 +00:00
|
|
|
ContractPart = StateVariableDeclaration | StructDefinition | ModifierDefinition | FunctionDefinition | 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-14 21:41:32 +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' )*
|
2014-10-08 18:53:50 +00:00
|
|
|
( 'returns' ParameterList )? Block
|
2015-02-13 21:56:46 +00:00
|
|
|
|
|
|
|
EnumValue = Identifier
|
2016-07-18 23:03:41 +00:00
|
|
|
EnumDefinition = 'enum' Identifier '{' EnumValue? (',' EnumValue)* '}'
|
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
|
2014-12-16 13:46:17 +00:00
|
|
|
VardefOrExprStmt = Variabledefinition | ExpressionStatement
|
|
|
|
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-18 23:26:39 +00:00
|
|
|
IndexAccess = Identifier ('[' Expression? ']')+
|
2014-10-09 13:57:49 +00:00
|
|
|
PrimaryExpression = Identifier | NumberLiteral | StringLiteral | ElementaryTypeName | '(' Expression ')'
|