#include "bnf.h" std::map> Reverse(BNF bnf){ std::map> result; for (const auto& [from, to] : bnf) { for (const auto& list : to) { for (const auto& element : list) { auto i{result.find(element)}; if (i != result.end()) // already present i->second.insert(from); else // new element result.emplace(element, std::set{from}); } } } return result; }