solidity/libsolidity/grammar.txt

54 lines
2.8 KiB
Plaintext
Raw Normal View History

ContractDefinition = ( 'contract' | 'library' ) Identifier
( 'is' InheritanceSpecifier (',' InheritanceSpecifier )* )?
'{' ContractPart* '}'
2015-02-13 21:56:46 +00:00
ContractPart = StateVariableDeclaration | StructDefinition | ModifierDefinition | FunctionDefinition | EnumDefinition
InheritanceSpecifier = Identifier ( '(' Expression ( ',' Expression )* ')' )?
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 ';'
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' )*
( 'returns' ParameterList )? Block
2015-02-13 21:56:46 +00:00
EnumValue = Identifier
EnumDefinition = 'enum' Identifier '{' EnumValue? (',' EnumValue)* '}'
ParameterList = '(' ( VariableDeclaration (',' VariableDeclaration)* )? ')'
// semantic restriction: mappings and structs (recursively) containing mappings
// are not allowed in argument lists
VariableDeclaration = TypeName Identifier
TypeName = ElementaryTypeName | Identifier | Mapping | ArrayTypeName
Mapping = 'mapping' '(' ElementaryTypeName '=>' TypeName ')'
ArrayTypeName = TypeName '[' Expression? ']'
Block = '{' Statement* '}'
Statement = IfStatement | WhileStatement | ForStatement | Block |
( Continue | Break | Return | Throw | VariableDefinition | ExpressionStatement ) ';'
ExpressionStatement = Expression
IfStatement = 'if' '(' Expression ')' Statement ( 'else' Statement )?
WhileStatement = 'while' '(' Expression ')' Statement
VardefOrExprStmt = Variabledefinition | ExpressionStatement
ForStatement = 'for' '(' (VardefOrExprStmt)? ';' (Expression)? ';' (ExpressionStatement)? ')' Statement
Continue = 'continue'
Break = 'break'
Return = 'return' Expression?
Throw = 'throw'
VariableDefinition = VariableDeclaration ( '=' Expression )?
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
// The expression syntax is actually much more complicated
Assignment = Expression (AssignmentOp Expression)
AssignmentOp = '|=' | '^=' | '&=' | '<<=' | '>>=' | '+=' | '-=' | '*=' | '/=' | '%='
2016-07-14 21:41:32 +00:00
UnaryOperation = '!' | '~' | '++' | '--' | 'delete'
BinaryOperation = '|' | '^' | '&' | '<<' | '>>' | '+' | '-' | '*' | '/' | '%'
| '||' | '&&' | '**' | '==' | '!=' | '<' | '>' | '<=' | '>='
2016-07-14 21:41:32 +00:00
FunctionCall = Identifier '(' Expression? ( ',' Expression )* ')'
2015-01-13 17:12:19 +00:00
NewExpression = 'new' Identifier
MemberAccess = Expression '.' Identifier
IndexAccess = Identifier ('[' Expression? ']')+
PrimaryExpression = Identifier | NumberLiteral | StringLiteral | ElementaryTypeName | '(' Expression ')'