aboutsummaryrefslogtreecommitdiff
path: root/language
diff options
context:
space:
mode:
Diffstat (limited to 'language')
-rw-r--r--language/source-file.rst2
-rw-r--r--language/statements/structure.rst42
2 files changed, 42 insertions, 2 deletions
diff --git a/language/source-file.rst b/language/source-file.rst
index 162bb88..079ee39 100644
--- a/language/source-file.rst
+++ b/language/source-file.rst
@@ -2,7 +2,7 @@ Source Files
------------
.. crowbar:element:: HeaderFile <- IncludeStatement* HeaderFileElement+
- HeaderFileElement <- TypeDefinition / FunctionDeclaration / ConstantDefinition / VariableDeclaration
+ HeaderFileElement <- TypeDefinition / FunctionDeclaration / VariableDefinition / VariableDeclaration
A Crowbar header file defines an API boundary, either at the surface of a library or between pieces of a library or application.
:crowbar:ref:`IncludeStatement`\ s can only appear at the beginning of the header file, and header files cannot define behavior directly.
diff --git a/language/statements/structure.rst b/language/statements/structure.rst
index 1a412af..0586608 100644
--- a/language/statements/structure.rst
+++ b/language/statements/structure.rst
@@ -20,7 +20,7 @@ Structure Statements
If the expression evaluates to a ``bool`` value of ``true``, then the first block will be executed.
If the expression evaluates to a ``bool`` value of ``false``, either the second block is executed or nothing is executed.
-.. crowbar.element.. SwitchStatement <- 'switch' '(' Expression ')' '{' (CaseSpecifier / Statement)+ '}'
+.. crowbar:element:: SwitchStatement <- 'switch' '(' Expression ')' '{' (CaseSpecifier / Statement)+ '}'
CaseSpecifier <- 'case' Expression ':' / 'default' ':'
A switch statement allows many different actions to be taken depending on the value of some expression.
@@ -39,3 +39,43 @@ Structure Statements
Any case specifiers immediately following the matching case specifier is ignored.
Subsequent statements are then executed, in linear order, until another case specifier is reached.
The execution of the switch statement then ends.
+
+.. crowbar:element:: WhileStatement <- 'while' '(' Expression ')' Block
+
+ Compile-time Behavior:
+
+ The expression must have type bool.
+
+ Runtime Behavior:
+
+ The expression is evaluated, and, if it evaluates to true, the block is executed.
+ This process repeats until the expression evaluates to false.
+
+.. crowbar:element:: DoWhileStatement <- 'do' Block 'while' '(' Expression ')' ';'
+
+ Compile-time Behavior:
+
+ The expression must have type bool.
+
+ Runtime Behavior:
+
+ The block is executed.
+ Then, the expression is evaluated, and if it is true the process repeats.
+
+.. crowbar:element:: ForStatement <- 'for' '(' ForInit? ';' Expression ';' ForUpdate? ')' Block
+ ForInit <- ForInitializer (',' ForInitializer)* ','?
+ ForInitializer <- Type identifier '=' Expression
+ ForUpdate <- AssignmentBody (',' AssignmentBody)* ','?
+
+ Compile-time Behavior:
+
+ The individual initializers each have the same behavior as a :crowbar:ref:`VariableDefinition`, but for scope purposes they are treated as though they are inside the block.
+ The top-level expression in the for statement must have type bool, and will be treated for scope purposes as though it is inside the block.
+ The update assignments will be treated for scope purposes as though they are inside the block.
+
+ Runtime Behavior:
+
+ First, the initializers are executed the same way variable definitions would be, in the order they are presented.
+ Then, the top-level expression is evaluated, and if it is false the for statement ends.
+ If the top-level expression was true, the block is executed, and then the update assignments are executed in the order they are presented.
+ The process repeats starting with expression evaluation.