From 752b10d4b0b607344d6ef2113231378ec295d3b8 Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Sun, 30 Mar 2014 16:21:25 +0100 Subject: Broke out NDFA into a subclass of Machine --- lib/machine.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/machine.rb diff --git a/lib/machine.rb b/lib/machine.rb new file mode 100644 index 0000000..ae8b6de --- /dev/null +++ b/lib/machine.rb @@ -0,0 +1,42 @@ +module VFSM + class Machine + attr_reader :currentnodes + + def initialize(machineDefinition) + @currentnodes = [] + end + + def handleinput(inputString) + end + + class << self + def printnodes nodes + print "{ " + (0..(nodes.length - 1)).each do |x| + if nodes[x].accepting? then + print "((#{nodes[x].id}))" + else + print "(#{nodes[x].id})" + end + print ", " unless x == (nodes.length - 1) + end + print " }" + end + + def recurse nodeslist + begin + oldlist = nodeslist.dup + oldlist.each do |node| + tmp = node.goto :lambda + unless tmp == :reject then + tmp.each do |x| + nodeslist.push x + end + end + end + nodeslist.uniq! + end while oldlist != nodeslist + end + end + end +end -- cgit v1.2.1