Combining Programs and State Machines
Basic instruction set
A basic instruction sets that supports interactions with state machines is FMN (Focus Method Notation).Instructions
f.a(x)- Here,
fis the focus of the instruction, anda(x)its co-instruction part (or co-action). The bracket pair can be empty. A focus is loaded the first time it is used.
It returns the value replied by the co-instruction. f.p:a(x)- Here,
pis the prefix of the action that will be performed, indicating a particular copy of the state machine. A copy of the state machines is created the first time the prefix is used.
It returns the value replied by the co-instruction.
f.a:xf:i.a:x- Here,
iis the instance of the method.
Available state machines
- Console
Co-actions:println(s)in whichsis a string of characters.
The actionprintlnprints its argument. - smbr - boolean register
Co-actions:set(true),set(false),eq(true),eq(false)
The co-actionsset(true)andset(false)replytrue. The co-actionseq(true)andeq(false)replyfalseuntil the register is set, after whicheq(b)repliestruewheneverbis the current value of the register, andfalseotherwise. - smnnr - natural number register
Co-actions:set(i),eq(i)in whichiis a natural number
The replies of the co-actions are simular to that of smbr. - smnnc - natural number counter
Co-actions:succ(),pred(),isZero()
The counter always starts with value zero, and the actionpred()leaves the counter at zero if it is zero. - smnns - natural number stack
Co-action:push(i),pop(),topEq(i)in whichiis a natural number.
The stack always starts empty, and the actionpop()leaves the empty stack empty.
Examples
- Consider the following PGLEc program.
smbr.x:set(true); smbr.y:set(false); + smbr.x:eq(true) {; Console.println(x is true); }{; Console.println(x is false); }; + smbr.y:eq(true) {; Console.println(y is true); }{; Console.println(y is false); }Upon execution the result will be:
x is true y is false
- Fibonacci numbers