diff options
Diffstat (limited to 'bnf.cpp')
-rw-r--r-- | bnf.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -0,0 +1,21 @@ +#include "bnf.h" + +std::map<std::string, std::set<std::string>> Reverse(BNF bnf){ + std::map<std::string, std::set<std::string>> 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; +} + + |