aboutsummaryrefslogtreecommitdiff
path: root/language
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
parent5f78969d4a71908fd8ae43c886614ef0e5664eb0 (diff)
downloadspec-e59e69118302b6a8a9d8c09ed2d5032d432ad33a.tar.gz
spec-e59e69118302b6a8a9d8c09ed2d5032d432ad33a.zip
add loops
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.