plxvm/doc/control.md

61 lines
3.0 KiB
Markdown

## Program Control
### Statement block
A statement block binds single statements enclosed in a curled paranthesis pair.
```
{ Φ Φ Φ .. }
```
### Conditional Branches
There is only a `if then else` statement branching to conditional statements. Conditional statements can be replaced by statement blocks, too.
| Statement | Description |
|:--|:--|
| `if ε:Φ:Φ:.. ` | If expression ε is true (not equal 0), then the following line statements are executed. |
| `if ε then Φ:Φ:.. ` | If expression ε is true (not equal 0), then the following line statements are executed. |
| `if ε { Φ }` | If expression ε is true (not equal 0), then the following block statement is executed. |
| `if ε then { Φ }` | If expression ε is true (not equal 0), then the following block statement is executed. |
| `if ε Φ1 else Φ2` | If expression ε is true (not equal 0), then the following statement Φ1 is executed else Φ2. |
| `if ε { Φ1 } else { Φ1 }` | If expression ε is true (not equal 0), then the following block statement Φ1 is executed, else Φ2. |
### Loops
There are conuting, conditional, and unconditional loops. Body statements can be replaced by statement blocks, too.
| Statement | Description | F-Stack Frame |
|:--|:--|
| `for i = a,b: Φ: Φ: ..` | Counting loop starting with *i*=*a* and terminating with i=b. The default increment value is one. | F(b,control address,end address,'F') |
| `for i = a,b do Φ: Φ: ..` | Counting loop starting with *i*=*a* and terminating with i=b. The default increment value is one. | F(b,control address,end address,'F') |
| `for i = a,b,s: Φ: Φ: ..` | Counting loop starting with *i*=*a* and looping as long as *i*<=*b*. The increment value (step size) is *s*. | F(b,step,control address,end address,'F') |
| `while ε: Φ: Φ: ..` | Conditional loop checking the expression ε at start. | F(start address,end address, 'W') |
| `while ε do Φ: Φ: ..` | Conditional loop checking the expression ε at start. | F(start address,end address, 'W') |
| `do Φ: Φ: .. while ε` | Conditional loop checking the expression ε at end. | F(start address,end address, 'D') |
| `repeat Φ` | Endless (service) loop, but breakable. | F(start address,end address, 'D') |
| `break` | Leave current (innerst) loop | - |
| `continue` | Branch to end of loop body (starting new loop iteration) | - |
### Functions and Procedures
| Statement | Description | F-Stack Frame |
|:--|:--|
| `proc pname { Φ } ` | Defines a procedure (no arguments, no return value) | - |
| `func fname(a,b,c) { Φ } ` | Defines a function with arguments (a,b,c) and a return value. | - |
| `return` | Return from procedure call (no return value) | - |
| `return ε` | Return from function call with return value ε | - |
| `call pname` | Call procedure | F() |
| `call fname(ε,..)` | Call function without return value | F() |
| `x=call fname(ε,..)` | Call function (in expression) with return value | F() |
### Program Flow Control
| Statement | Description | F-Stack Frame |
|:--|:--|
| `go` | Resume program | - |
| `stop` | Suspend program | - |