aboutsummaryrefslogtreecommitdiff
path: root/language/statements
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-11-02 21:36:36 -0700
committerMelody Horn <melody@boringcactus.com>2020-11-02 21:36:36 -0700
commite59e69118302b6a8a9d8c09ed2d5032d432ad33a (patch)
tree74eb029a62f7ffd482fa6968cc965ecc6dbd587c /language/statements
parent5f78969d4a71908fd8ae43c886614ef0e5664eb0 (diff)
downloadspec-e59e69118302b6a8a9d8c09ed2d5032d432ad33a.tar.gz
spec-e59e69118302b6a8a9d8c09ed2d5032d432ad33a.zip
add loops
Diffstat (limited to 'language/statements')
-rw-r--r--language/statements/structure.rst42
1 files changed, 41 insertions, 1 deletions
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.