#include "Transition.hpp" #include <regex> Transition::Transition(const std::string & name) { this->name = name; std::regex writeRegex("WRITE ([bs])\\.(.+) (.+) (.+)"); try { if (util::doIfNameMatch(writeRegex, name, [this](auto sm){initWrite(sm[3], sm[1], sm[2], sm[4]);})) return; throw std::invalid_argument("no match"); } catch (std::exception & e) {util::myThrow(fmt::format("Invalid name '{}' ({})", name, e.what()));} } void Transition::initWrite(std::string colName, std::string object, std::string index, std::string value) { auto objectValue = Action::str2object(object); int indexValue = std::stoi(index); sequence.emplace_back(Action::addHypothesisRelative(colName, objectValue, indexValue, value)); cost = [colName, objectValue, indexValue, value](const Config & config) { int lineIndex = 0; if (objectValue == Action::Object::Buffer) lineIndex = config.getWordIndex() + indexValue; else lineIndex = config.getStack(indexValue); if (config.getConst(colName, lineIndex, 0) == value) return 0; return 1; }; }