implement s-machine with mutually recursive funcs