require 'models' require 'bizzieStrings' def arraysIntersect(arrays) retArray = [] arrays[0].each do |elem| inc = true arrays[1..-1].each do |array| inc = inc && array.member?(elem) end if inc retArray << elem end end return retArray end class ModelInteractor def initialize @bindings = Hash.new end def processCommand(tokens) if tokens[0] == "create" processCreate(tokens) else tokens = processSubCommands(tokens) modelsCont = [] findBound(tokens).each do |token| modelsCont << @bindings[token] end modelsInt = arraysIntersect(modelsCont) modelsInt.each do |model| model.processCommand(tokens) end end end def processSubCommands(tokens) retTokens = [] tokens.each_index do |x| # do subexpression and return value if tokens.at(x) == "(" else retTokens << tokens.at(x) end end end def processCreate(tokens) type = tokens[1] name = tokens[2] models = findModelsByType(type) boundModels = [] models.each do |model| if model.create(type, tokens[2..-1]) boundModels << model end end @bindings[name] = boundModels end def findBound(tokens) retTokens = [] tokens.each do |token| if @bindings.key? token retTokens << token end end return retTokens end end class Parser def initialize @models = ModelInteractor.new end def readLine(line) tokens = tokenize(line) end def tokenize(line) return line.split end end