From c511559318c060343ced81defe6c3257df14f397 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sun, 15 Nov 2015 13:57:45 +0100 Subject: [PATCH] copy constr e-FreeCFG -> CFG --- alib2data/src/grammar/ContextFree/CFG.cpp | 13 +++++++++++++ alib2data/src/grammar/ContextFree/CFG.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/alib2data/src/grammar/ContextFree/CFG.cpp b/alib2data/src/grammar/ContextFree/CFG.cpp index 4171918174..b28525c0c1 100644 --- a/alib2data/src/grammar/ContextFree/CFG.cpp +++ b/alib2data/src/grammar/ContextFree/CFG.cpp @@ -18,6 +18,7 @@ #include "../Grammar.h" #include "../../object/Object.h" #include "../../XmlApi.hpp" +#include "../../CastApi.hpp" namespace grammar { @@ -30,6 +31,15 @@ CFG::CFG(std::set<alphabet::Symbol> nonterminalAlphabet, std::set<alphabet::Symb setTerminalAlphabet(std::move(terminalAlphabet)); } +CFG::CFG( const EpsilonFreeCFG & other ) : CFG(other.getNonterminalAlphabet(), other.getTerminalAlphabet(), other.getInitialSymbol()) { + for(const std::pair<alphabet::Symbol, std::set<std::vector<alphabet::Symbol>>> & rule : other.getRules() ) { + const alphabet::Symbol & lhs = rule.first; + for(const std::vector<alphabet::Symbol>& rhs : rule.second) { + addRule(lhs, rhs); + } + } +} + GrammarBase* CFG::clone() const { return new CFG(*this); } @@ -179,4 +189,7 @@ namespace alib { xmlApi<grammar::Grammar>::ParserRegister<grammar::CFG> CFGParserRegister = xmlApi<grammar::Grammar>::ParserRegister<grammar::CFG>(grammar::CFG::XML_TAG_NAME, grammar::CFG::parse); xmlApi<alib::Object>::ParserRegister<grammar::CFG> CFGParserRegister2 = xmlApi<alib::Object>::ParserRegister<grammar::CFG>(grammar::CFG::XML_TAG_NAME, grammar::CFG::parse); +auto CFGEpsilonFreeCFG = castApi::CastRegister<grammar::CFG, grammar::EpsilonFreeCFG>(); +auto CFGCastBinder = castApi::CastPoolStringBinder<grammar::CFG>(grammar::CFG::XML_TAG_NAME); + } /* namespace alib */ diff --git a/alib2data/src/grammar/ContextFree/CFG.h b/alib2data/src/grammar/ContextFree/CFG.h index 0eeb1ffba1..ee0d5e73ff 100644 --- a/alib2data/src/grammar/ContextFree/CFG.h +++ b/alib2data/src/grammar/ContextFree/CFG.h @@ -9,6 +9,7 @@ #define CFG_H_ #include "../GrammarBase.h" +#include "EpsilonFreeCFG.h" #include <map> #include <vector> #include "../common/TerminalNonterminalAlphabetInitialSymbol.h" @@ -26,6 +27,8 @@ public: explicit CFG ( std::set < alphabet::Symbol > nonTerminalSymbols, std::set < alphabet::Symbol > terminalSymbols, alphabet::Symbol initialSymbol ); + explicit CFG ( const EpsilonFreeCFG & other ); + virtual GrammarBase * clone ( ) const; virtual GrammarBase * plunder ( ) &&; -- GitLab