diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2022-09-04 00:34:09 +1200 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2022-09-04 00:34:09 +1200 |
| commit | e449c3c866b0c91a0bc34d5cb462c47b5fa43ce1 (patch) | |
| tree | bb4318c89ed75fefeeaeff7dcb4ae274c16772e6 /src/thue/program.cr | |
| parent | 00755963fe8d688733ae55a774d72e04de5981b4 (diff) | |
Able to interpret Thue
Diffstat (limited to 'src/thue/program.cr')
| -rw-r--r-- | src/thue/program.cr | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/thue/program.cr b/src/thue/program.cr index c59780b..f449f5a 100644 --- a/src/thue/program.cr +++ b/src/thue/program.cr @@ -6,8 +6,16 @@ class Thue::Program end def interpret - something = @parser.parse - puts something + rules, state = @parser.parse + + loop do + r = rules.find { |r| r.matches?(state) } + break if r.nil? + + state = state.sub(r.pattern, r.replacement) + end + + puts state end end |
