aboutsummaryrefslogtreecommitdiff
path: root/language/statements
diff options
context:
space:
mode:
Diffstat (limited to 'language/statements')
-rw-r--r--language/statements/index.rst23
-rw-r--r--language/statements/structure.rst21
-rw-r--r--language/statements/variables.rst24
3 files changed, 68 insertions, 0 deletions
diff --git a/language/statements/index.rst b/language/statements/index.rst
new file mode 100644
index 0000000..38bfbb1
--- /dev/null
+++ b/language/statements/index.rst
@@ -0,0 +1,23 @@
+Statements
+----------
+
+.. crowbar:element:: Block <- '{' Statement* '}'
+
+ Compile-time Behavior:
+
+ A block is a possibly-empty sequence of statements surrounded by curly braces.
+ Any declaration or definition within the block must not be visible outside of the block.
+
+ Runtime Behavior:
+
+ When a block is executed, each of the containing statements, in linear order, is executed.
+
+.. crowbar:element:: Statement <- VariableDefinition / StructureStatement / FlowControlStatement / AssignmentStatement / FragileStatement / ExpressionStatement
+
+ Crowbar has many different types of statement.
+
+.. toctree::
+ :maxdepth: 1
+
+ variables
+ structure
diff --git a/language/statements/structure.rst b/language/statements/structure.rst
new file mode 100644
index 0000000..9330bf6
--- /dev/null
+++ b/language/statements/structure.rst
@@ -0,0 +1,21 @@
+Structure Statements
+^^^^^^^^^^^^^^^^^^^^
+
+.. crowbar:element:: StructureStatement <- IfStatement / SwitchStatement / WhileStatement / DoWhileStatement / ForStatement
+
+ A structure statement creates some nonlinear control structure.
+ There are several types of these structures.
+
+.. crowbar:element:: IfStatement <- 'if' '(' Expression ')' Block ('else' Block)?
+
+ An if statement allows some action to be performed only sometimes, based on the value of the expression.
+
+ Compile-time Behavior:
+
+ If the expression does not have type bool, the compiler must emit an error.
+
+ Runtime Behavior:
+
+ First, the expression is evaluated.
+ 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.
diff --git a/language/statements/variables.rst b/language/statements/variables.rst
new file mode 100644
index 0000000..6bc1a6f
--- /dev/null
+++ b/language/statements/variables.rst
@@ -0,0 +1,24 @@
+Variables
+^^^^^^^^^
+
+.. crowbar:element:: VariableDeclaration <- Type identifier ';'
+
+ Compile-time Behavior:
+
+ A variable declaration specifies the type and name of a variable but not its initial value.
+ This is only used in :crowbar:ref:`HeaderFile`\ s as part of API boundaries.
+
+ Runtime Behavior:
+
+ A variable declaration has no runtime behavior.
+
+.. crowbar:element:: VariableDefinition <- Type identifier '=' Expression ';'
+
+ Compile-time Behavior:
+
+ A variable definition specifies the type, name, and initial value of a variable.
+ If the expression has a type which is not the type specified for the variable, an error must be emitted.
+
+ Runtime Behavior:
+
+ When a variable definition is executed, the expression is evaluated, and its result is made available with the given name.