Added switch statements to spec

This commit is contained in:
Sasha Koshka 2024-03-25 00:46:30 -04:00
parent 3cd3384006
commit 7e05785c09
1 changed files with 14 additions and 4 deletions

View File

@ -266,8 +266,15 @@ value. Each case takes the form of a declaration, and an associated expression.
If the type of the union matches the type of the declaration in the case, the
expression is executed and the value of the union is made available to it
through the declaration. If the value of the match expression is used, all
possible types in the union must be accounted for. It may be assigned to any
type that satisfies the assignment rules of its first case.
possible types in the union must be accounted for, or it must have a default
case. It may be assigned to any type that satisfies the assignment rules of its
first case.
### Switch
Switch is a control flow branching expression that executes one of several case
expressions depending on the value of the input. It accepts any pointer or
integer type. If the value of the switch expression is used, a default case must
be present. It may be assigned to any type that satisfies the assignment rules
of its first case.
### Loop
Loop is a control flow expression that repeats an expression until a break
statement is called from within it. The break statement must be given a value
@ -366,7 +373,8 @@ this without hand-writing a parser.
<ifelse> -> "if" <expression>
"then" <expression>
["else" <expression>]
<match> -> "match" <expression> <case>*
<match> -> "match" <expression> <matchCase>* [<defaultCase>]
<switch> -> "switch" <expression> <switchCase>* [<defaultCase>]
<loop> -> "loop" <expression>
<for> -> "for" <expression> [<expression>] in <expression> <expression>
<break> -> "[" "break" [<expression>] "]"
@ -384,7 +392,9 @@ this without hand-writing a parser.
<booleanLiteral> -> "true" | "false"
<member> -> <identifier> ":" <expression>
<case> -> "|" <declaration> <expression>
<matchCase> -> "|" <declaration> <expression>
<switchCase> -> "|" <expression> <expression>
<defaultCase> -> "*" <expression>
<signature> -> "[" <identifier> <declaration>* "]" [":" <type>]
<identifier> -> /[a-z][A-Za-z]*/
<typeIdentifier> -> /[A-Z][A-Za-z]*/