mirror of
https://github.com/vczh-libraries/Release.git
synced 2026-05-31 22:04:09 +08:00
Update TODO_StateMachine.md
This commit is contained in:
+123
-1
@@ -24,7 +24,7 @@
|
|||||||
- `$pass_input` statement
|
- `$pass_input` statement
|
||||||
- The next `$switch` will use the current input
|
- The next `$switch` will use the current input
|
||||||
|
|
||||||
#### Sample
|
### Sample
|
||||||
```
|
```
|
||||||
class Calculator
|
class Calculator
|
||||||
{
|
{
|
||||||
@@ -148,3 +148,125 @@ func Main(): string
|
|||||||
return calculator.Value; // "46"
|
return calculator.Value; // "46"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Generated
|
||||||
|
```
|
||||||
|
class Calculator
|
||||||
|
{
|
||||||
|
... // ignored everything before $state_machine
|
||||||
|
|
||||||
|
enum <state>Input
|
||||||
|
{
|
||||||
|
<state>Invalid = 0,
|
||||||
|
Digit = 1,
|
||||||
|
Dot = 2,
|
||||||
|
Add = 3,
|
||||||
|
Mul = 4,
|
||||||
|
Equal = 5,
|
||||||
|
Clear = 6,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum <state>State
|
||||||
|
{
|
||||||
|
<state>Start = 0,
|
||||||
|
Digit = 1,
|
||||||
|
Integer = 2,
|
||||||
|
Numver = 3,
|
||||||
|
Calculate = 4,
|
||||||
|
}
|
||||||
|
|
||||||
|
[cpp:Private]
|
||||||
|
var <state>input: <State>Input = ::Calculator::<state>Input::<state>Invalid;
|
||||||
|
|
||||||
|
[cpp:Private]
|
||||||
|
var <state>coroutine: ::system::Coroutine^ = null;
|
||||||
|
|
||||||
|
[cpp:Private]
|
||||||
|
var <statep-Digit>i: int = 0;
|
||||||
|
|
||||||
|
[cpp:Private]
|
||||||
|
void <state>Resume(): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Digit(i: int): void { <state>input = ::Calculator::<state>Input::Digit; <statep-Digit>i = i; <state>Resume(); }
|
||||||
|
void Dot(): void { <state>input = ::Calculator::<state>Input::Dot; <state>Resume(); }
|
||||||
|
void Add(): void { <state>input = ::Calculator::<state>Input::Add; <state>Resume(); }
|
||||||
|
void Mul(): void { <state>input = ::Calculator::<state>Input::Mul; <state>Resume(); }
|
||||||
|
void Equal(): void { <state>input = ::Calculator::<state>Input::Equal; <state>Resume(); }
|
||||||
|
void Clear(): void { <state>input = ::Calculator::<state>Input::Clear; <state>Resume(); }
|
||||||
|
|
||||||
|
void RunStateMachine(): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
$state_machine
|
||||||
|
{
|
||||||
|
$state Digits()
|
||||||
|
{
|
||||||
|
$switch(pass)
|
||||||
|
{
|
||||||
|
case Digit(i)
|
||||||
|
{
|
||||||
|
Value = Value & i;
|
||||||
|
$goto_state Digits();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$state Integer(newNumber: bool)
|
||||||
|
{
|
||||||
|
$switch(pass)
|
||||||
|
{
|
||||||
|
case Digit(i)
|
||||||
|
{
|
||||||
|
if (newNumber)
|
||||||
|
{
|
||||||
|
Value = i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Value = Value & i;
|
||||||
|
}
|
||||||
|
$goto_state Digits();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$state Number()
|
||||||
|
{
|
||||||
|
$push_state Integer(true);
|
||||||
|
$switch(pass_and_return)
|
||||||
|
{
|
||||||
|
case Dot()
|
||||||
|
{
|
||||||
|
Value = Value & ".";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$push_state Integer(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$state Calculate()
|
||||||
|
{
|
||||||
|
$push_state Number();
|
||||||
|
$switch
|
||||||
|
{
|
||||||
|
case Add(): {Calculate(); op = "+";}
|
||||||
|
case Mul(): {Calculate(); op = "-";}
|
||||||
|
case Equal(): {Calculate(); op = "=";}
|
||||||
|
case Clear():
|
||||||
|
{
|
||||||
|
valueFirst = "";
|
||||||
|
op = "";
|
||||||
|
Value = "0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$state
|
||||||
|
{
|
||||||
|
$goto_state Calculate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user