aboutsummaryrefslogblamecommitdiffstats
path: root/libsolidity/grammar.txt
blob: 08a74f458fd2f689c8fbc6c5a80dbe3f338dd7c2 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                          

                                                                                
                                                                                                                     
 
                                                                             

                                                                           
                                                                                            
                                                               
                                                        
                                                                                                                         
                                                       

                      
                                                          
                                                                           


                                                                               
                                                                    
                                                            
                                              

                          
                                                  
                                                                                                    
 
                                

                                                                     

                                                                                                       


                                 
                               
                                                              
 
                                                                                                         

                                                          
                                                 
                                                                
                                
                                        
                                              
                                                                                                        
ContractDefinition = ( 'contract' | 'library' ) Identifier
                     ( 'is' InheritanceSpecifier (',' InheritanceSpecifier )* )?
                     '{' ContractPart* '}'
ContractPart = StateVariableDeclaration | StructDefinition | ModifierDefinition | FunctionDefinition | EnumDefinition

InheritanceSpecifier = Identifier ( '(' Expression ( ',' Expression )* ')' )?
StructDefinition = 'struct' Identifier '{'
                     ( VariableDeclaration (';' VariableDeclaration)* )? '}
StateVariableDeclaration = TypeName ( 'public' | 'inheritable' | 'private' )? Identifier ';'
ModifierDefinition = 'modifier' Identifier ParameterList? Block
FunctionDefinition = 'function' Identifier ParameterList
                     ( Identifier | 'constant' | 'external' | 'public' | 'inheritable' | 'private' )*
                     ( 'returns' ParameterList )? Block

EnumValue = Identifier
EnumDefinition = 'enum' '{' 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 | Block |
            ( Continue | Break | Return | 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' Expression? ';'
VariableDefinition = VariableDeclaration ( = Expression )? ';'

Expression = Assignment | UnaryOperation | BinaryOperation | FunctionCall | NewExpression | IndexAccess |
             MemberAccess | PrimaryExpression
// The expression syntax is actually much more complicated
Assignment = Expression (AssignmentOp Expression)
FunctionCall = Expression '(' Expression ( ',' Expression )* ')'
NewExpression = 'new' Identifier
MemberAccess = Expression '.' Identifier
IndexAccess = Expression '[' (Expresison)? ']'
PrimaryExpression = Identifier | NumberLiteral | StringLiteral | ElementaryTypeName | '(' Expression ')'