summaryrefslogtreecommitdiffhomepage
path: root/bnf.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-01-21 22:49:30 +0100
committerRoland Reichwein <mail@reichwein.it>2020-01-21 22:49:30 +0100
commitf4b2027868c9733bbbbcb4c5ec6d5462a8447e5d (patch)
tree40ce459f1a501d6c88936c78f6dbcbb8aadd04ca /bnf.cpp
parent08997620fd617b580c1adbcb03c90cf621aa7069 (diff)
Separate to cpp files
Diffstat (limited to 'bnf.cpp')
-rw-r--r--bnf.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/bnf.cpp b/bnf.cpp
new file mode 100644
index 0000000..1efb459
--- /dev/null
+++ b/bnf.cpp
@@ -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;
+}
+
+