Last active
July 21, 2017 22:05
-
-
Save rgchris/67cd497c097d7ff768a15424057bbdea to your computer and use it in GitHub Desktop.
Contrived Parse-based FSM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/red | |
Red [ | |
Title: "Contrived FSM Example" | |
Date: 21-Jul-2017 | |
Author: "Christopher Ross-Gill" | |
] | |
state: mark: none | |
use: func ['target [word!]][ | |
probe to tag! target | |
state: get in states target | |
] | |
states: make object! [ | |
is-a: [ | |
#"a" (print "A in A") | |
| #"b" (print "B in A" use is-b) | |
| end (print "End in A") fail | |
] | |
is-b: [ | |
mark: #"a" (print "A in B" use is-a) :mark | |
| #"b" (print "B in B") | |
| end (print "End in B" use is-a) | |
] | |
] | |
parse-abba: func [series [string!]][ | |
use is-a | |
parse series [while [state]] | |
] | |
parse-abba probe "aba" | |
print "" | |
parse-abba probe "bab" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment