summaryrefslogtreecommitdiff
path: root/src/thue/program.cr
blob: 96e1284dea9b7f353b130d264891472dee2c4cf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require "./thue.cr"
require "./parser.cr"
require "../util.cr"

class Thue::Program
  def initialize(@parser : Parser)
  end

  def interpret
    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

  def compile
    raise Util::NoCompilerAvailableError.new("No available compilier for Thue")
  end
end