[NAME]
ALL.dao.grammar.statement

[TITLE]
Statements

[DESCRIPTION]

Drafting in progress.

 0.1   Declaration Statements  

     
   1  ConstStatic    ::= 'const' | 'static'
   2  VarGlobal      ::= 'var' | 'invar'
   3  IdentifierList ::= Identifier {',' Identifier }
   4  
   5  ConstStaticDecl ::= ConstStatic IdentifierList [ ':' Type ] [ '=' ConstExpression ]
   6  VarGlobalDecl   ::= VarGlobal   IdentifierList [ ':' Type ] [ '=' Expression ]
   7  
   8  DeclarationStmt ::= ConstStaticDecl | VarGlobalDecl
     


 0.2   Basic Statement  

     
   1  BasicStatement ::= DeclarationStmt | Expression | 'break' | 'skip'
     


 0.3   If-else Statement  

     
   1  ControlBlock ::= Statement | '{' [ StatementBlock ] '}'
   2  
   3  IfElseStmt ::= 'if' '(' [ LocalVarDeclaration ';' ] Expression ')' ControlBlock
   4                 { 'else' 'if' '(' [ LocalVarDeclaration ';' ] Expression  ')' ControlBlock }
   5                 [ 'else' ControlBlock ]
     


 0.4   For Loop Statement  

     
   1  ForIn ::= 'for' '(' [ 'var' ] Identifier 'in' Expression {';' Identifier 'in' Expression} ')'
   2                ControlBlock
   3  
   4  RangeFor ::= 'for' '(' [ 'var' ] Identifier '=' Expression ':' [ Expression ':' ] Expression ')'
   5                ControlBlock
   6  
   7  CFor  ::= 'for' '(' [ LocalVarDeclaration ] ';' [ Expression ] ';' [ ExpressionList ] ')'
   8                ControlBlock
   9  
  10  ForStmt ::= ForIn | RangeFor | CFor
     


 0.5   While Loop Statement  

     
   1  WhileStmt ::= 'while' '(' [ LocalVarDeclaration ';' ] Expression ')' ControlBlock
     


 0.6   Do-while Looping Statement  

     
   1  DoWhileStmt ::= 'do' ControlBlock 'while' '(' Expression ')'
     


 0.7   Switch-case Statement  

     
   1  ValueSwitch ::= 'switch' '(' [ ('var' | 'invar') '=' ] Expression ')' '{'
   2                     { 'case' ConstExpression [ ( ',' | '...' ) ConstExpression ] ':' 
   3                                     ControlBlock }
   4                     [ 'default' ':' ControlBlock ]
   5                     '}'
   6  
   7  TypeSwitch ::= 'switch' '(' [ ('var' | 'invar') '=' ] Expression ')' 'type' '{'
   8                     { 'case' Type [ ( ',' | '...' ) Type ] ':' ControlBlock }
   9                     [ 'default' ':' ControlBlock ]
  10                     '}'
  11  
  12  SwitchCaseStmt ::= ValueSwitch | TypeSwitch
     


 0.8   Defer Statement  

     
   1  DeferStmt ::= 'defer' [ '(' [ Type ] ')' ] '{' StatementBlock '}'
     


 0.9   Type Aliasing Statement  

     
   1  TypeAlias ::= 'type' Identifier '=' Type
     


 0.10   Load Statement  

     
   1  LoadFile ::= 'load' ( String | { Identifier ('.' | '::') } Identifier ) [ 'as' Identifier ]
   2  LoadResultMod ::= 'load' Identifier '(' [ ConstArgumentItem { ',' ConstArgumentItem } ')'
   3  
   4  LoadStmt ::= LoadFile | LoadResultMod
     


 0.11   Import Statement  

     
   1  SingleImport ::= 'import' Identifier '.' Identifier
   2  MultipleImport ::= 'import' Identifier '.' '{' [ IdentifierList ] '}'
   3  
   4  ImportStmt ::= SingleImport | MultipleImport
     
Import the constants and globals from another namespace to the current scope.

 0.12   Yield Statement  

     
   1  YieldStmt ::= 'yield' '(' [ ArgumentList ] ')'
     


 0.13   Return Statement  

     
   1  ReturnStmt ::= 'return' [ ExpressionList ]
     


 0.14   Statement and Block  


     
   1  Statement ::= DeclarationStmt
   2              | BasicStatement
   3              | IfElseStmt
   4              | ForStmt
   5              | WhileStmt
   6              | DoWhileStmt
   7              | SwitchCaseStmt
   8              | DeferStmt
   9              | TypeAlias
  10              | LoadStmt
  11              | ImportStmt
  12              | YieldStmt
  13              | ReturnStmt
  14  
  15  StatementBlock ::= { Statement }
     
Note: the LoadStmt is only allowed at the top lexical scope.