diff --git a/alib2/src/FromXMLParsers.cpp b/alib2/src/FromXMLParsers.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dfa40a1af3bc226f89a4458646e02e02cbf3ef52 --- /dev/null +++ b/alib2/src/FromXMLParsers.cpp @@ -0,0 +1,18 @@ +/* + * FromXMLParsers.cpp + * + * Created on: Apr 1, 2013 + * Author: Jan Travnicek + */ + +#include "FromXMLParsers.h" + +namespace alib { + +const label::LabelFromXMLParser FromXMLParsers::labelParser; +const alphabet::SymbolFromXMLParser FromXMLParsers::symbolParser; +const regexp::RegExpFromXMLParser FromXMLParsers::regexpParser; +const string::StringFromXMLParser FromXMLParsers::stringParser; +const automaton::AutomatonFromXMLParser FromXMLParsers::automatonParser; + +} /* namespace alib */ diff --git a/alib2/src/FromXMLParsers.h b/alib2/src/FromXMLParsers.h new file mode 100644 index 0000000000000000000000000000000000000000..f28400e7010b110fba99bbf0a1724488c90b782e --- /dev/null +++ b/alib2/src/FromXMLParsers.h @@ -0,0 +1,35 @@ +/* + * FromXMLParsers.h + * + * Created on: Apr 1, 2013 + * Author: Jan Travnicek + */ + +#ifndef FROM_XML_PARSERS_H_ +#define FROM_XML_PARSERS_H_ + +#include "label/LabelFromXMLParser.h" +#include "alphabet/SymbolFromXMLParser.h" +#include "regexp/RegExpFromXMLParser.h" +#include "string/StringFromXMLParser.h" +#include "automaton/AutomatonFromXMLParser.h" + +namespace alib { + +/** + * Basic exception from which are derived all other exceptions. + * Contains reason why the exception occured. + */ +class FromXMLParsers { +public: + static const label::LabelFromXMLParser labelParser; + static const alphabet::SymbolFromXMLParser symbolParser; + static const regexp::RegExpFromXMLParser regexpParser; + static const string::StringFromXMLParser stringParser; + static const automaton::AutomatonFromXMLParser automatonParser; + +}; + +} /* namespace alib */ + +#endif /* FROM_XML_PARSERS_H_ */ diff --git a/alib2/src/ToXMLComposers.cpp b/alib2/src/ToXMLComposers.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9283a3c77792e1e8ca0d1d1e9fa935fa5890c26 --- /dev/null +++ b/alib2/src/ToXMLComposers.cpp @@ -0,0 +1,18 @@ +/* + * ToXMLComposers.cpp + * + * Created on: Apr 1, 2013 + * Author: Jan Travnicek + */ + +#include "ToXMLComposers.h" + +namespace alib { + +const label::LabelToXMLComposer ToXMLComposers::labelComposer; +const alphabet::SymbolToXMLComposer ToXMLComposers::symbolComposer; +const regexp::RegExpToXMLComposer ToXMLComposers::regexpComposer; +const string::StringToXMLComposer ToXMLComposers::stringComposer; +const automaton::AutomatonToXMLComposer ToXMLComposers::automatonComposer; + +} /* namespace alib */ diff --git a/alib2/src/ToXMLComposers.h b/alib2/src/ToXMLComposers.h new file mode 100644 index 0000000000000000000000000000000000000000..9882e6528395e5e418fe6df0dcb87c54ea5667fe --- /dev/null +++ b/alib2/src/ToXMLComposers.h @@ -0,0 +1,35 @@ +/* + * ToXMLComposers.h + * + * Created on: Apr 1, 2013 + * Author: Jan Travnicek + */ + +#ifndef TO_XML_COMPOSERS_H_ +#define TO_XML_COMPOSERS_H_ + +#include "label/LabelToXMLComposer.h" +#include "alphabet/SymbolToXMLComposer.h" +#include "regexp/RegExpToXMLComposer.h" +#include "string/StringToXMLComposer.h" +#include "automaton/AutomatonToXMLComposer.h" + +namespace alib { + +/** + * Basic exception from which are derived all other exceptions. + * Contains reason why the exception occured. + */ +class ToXMLComposers { +public: + static const label::LabelToXMLComposer labelComposer; + static const alphabet::SymbolToXMLComposer symbolComposer; + static const regexp::RegExpToXMLComposer regexpComposer; + static const string::StringToXMLComposer stringComposer; + static const automaton::AutomatonToXMLComposer automatonComposer; + +}; + +} /* namespace alib */ + +#endif /* TO_XML_COMPOSERS_H_ */ diff --git a/alib2/src/alphabet/SymbolFromXMLParser.cpp b/alib2/src/alphabet/SymbolFromXMLParser.cpp index e7cc5c61a8f9775dd91af808bebd18bcc802e262..1c66d9f1d747f66ed9d4844d6b91b14e2418f726 100644 --- a/alib2/src/alphabet/SymbolFromXMLParser.cpp +++ b/alib2/src/alphabet/SymbolFromXMLParser.cpp @@ -15,7 +15,7 @@ namespace alphabet { -Symbol SymbolFromXMLParser::parse(std::list<sax::Token>& input) { +Symbol SymbolFromXMLParser::parse(std::list<sax::Token>& input) const { if(isToken(input, sax::Token::START_ELEMENT, "LabeledSymbol")) { popToken(input, sax::Token::START_ELEMENT, "LabeledSymbol"); label::Label data = parseContent(input); @@ -30,7 +30,7 @@ Symbol SymbolFromXMLParser::parse(std::list<sax::Token>& input) { } } -label::Label SymbolFromXMLParser::parseContent(std::list<sax::Token>& input) { +label::Label SymbolFromXMLParser::parseContent(std::list<sax::Token>& input) const { if (isTokenType(input, sax::Token::CHARACTER)) { label::Label data(label::StringLabel(input.front().getData())); input.pop_front(); diff --git a/alib2/src/alphabet/SymbolFromXMLParser.h b/alib2/src/alphabet/SymbolFromXMLParser.h index 112ab6fa2168c65ba277afc4d89cfbb4d1e7e29e..b41909c0518bf9ff2fdd414b365e24a9a2fc064d 100644 --- a/alib2/src/alphabet/SymbolFromXMLParser.h +++ b/alib2/src/alphabet/SymbolFromXMLParser.h @@ -20,7 +20,7 @@ namespace alphabet { * Parser used to get String from XML parsed into list of tokens. */ class SymbolFromXMLParser : public sax::FromXMLParser { - label::Label parseContent(std::list<sax::Token>& input); + label::Label parseContent(std::list<sax::Token>& input) const; public: /** @@ -29,7 +29,7 @@ public: * @return String * @throws ParserException when an error occurs */ - Symbol parse(std::list<sax::Token>& input); + Symbol parse(std::list<sax::Token>& input) const; }; diff --git a/alib2/src/automaton/AutomatonFromXMLParser.cpp b/alib2/src/automaton/AutomatonFromXMLParser.cpp index f79d0c96c2203e0a25fc1f46d2b48d24ee28f0e5..cf739ee2a50b16e8546440db5c7e716b34314607 100644 --- a/alib2/src/automaton/AutomatonFromXMLParser.cpp +++ b/alib2/src/automaton/AutomatonFromXMLParser.cpp @@ -15,7 +15,7 @@ namespace automaton { -Automaton AutomatonFromXMLParser::parse(std::list<sax::Token> &input) { +Automaton AutomatonFromXMLParser::parse(std::list<sax::Token> &input) const { if(isToken(input, sax::Token::START_ELEMENT, "automaton")) return Automaton(parseUnknownAutomaton(input)); else if(isToken(input, sax::Token::START_ELEMENT, "EpsilonNFA")) @@ -28,7 +28,7 @@ Automaton AutomatonFromXMLParser::parse(std::list<sax::Token> &input) { throw sax::ParserException(sax::Token("EpsilonNFA / NFA / DFA", sax::Token::START_ELEMENT), input.front()); } -UnknownAutomaton AutomatonFromXMLParser::parseUnknownAutomaton(std::list<sax::Token> &input) { +UnknownAutomaton AutomatonFromXMLParser::parseUnknownAutomaton(std::list<sax::Token> &input) const { UnknownAutomaton automaton; popToken(input, sax::Token::START_ELEMENT, "automaton"); @@ -62,7 +62,7 @@ UnknownAutomaton AutomatonFromXMLParser::parseUnknownAutomaton(std::list<sax::To return automaton; } -DFA AutomatonFromXMLParser::parseDFA(std::list<sax::Token>& input) { +DFA AutomatonFromXMLParser::parseDFA(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "DFA"); std::set<State> states = parseStates(input); @@ -81,7 +81,7 @@ DFA AutomatonFromXMLParser::parseDFA(std::list<sax::Token>& input) { return automaton; } -NFA AutomatonFromXMLParser::parseNFA(std::list<sax::Token>& input) { +NFA AutomatonFromXMLParser::parseNFA(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "NFA"); std::set<State> states = parseStates(input); @@ -101,7 +101,7 @@ NFA AutomatonFromXMLParser::parseNFA(std::list<sax::Token>& input) { return automaton; } -EpsilonNFA AutomatonFromXMLParser::parseEpsilonNFA(std::list<sax::Token>& input) { +EpsilonNFA AutomatonFromXMLParser::parseEpsilonNFA(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "EpsilonNFA"); std::set<State> states = parseStates(input); @@ -121,11 +121,11 @@ EpsilonNFA AutomatonFromXMLParser::parseEpsilonNFA(std::list<sax::Token>& input) return automaton; } -std::string AutomatonFromXMLParser::parseLabel(std::list<sax::Token>& input) { +std::string AutomatonFromXMLParser::parseLabel(std::list<sax::Token>& input) const { return popTokenData(input, sax::Token::CHARACTER); } -std::set<State> AutomatonFromXMLParser::parseStates(std::list<sax::Token> &input) { +std::set<State> AutomatonFromXMLParser::parseStates(std::list<sax::Token> &input) const { std::set<State> states; popToken(input, sax::Token::START_ELEMENT, "states"); while (isTokenType(input, sax::Token::START_ELEMENT)) { @@ -137,7 +137,7 @@ std::set<State> AutomatonFromXMLParser::parseStates(std::list<sax::Token> &input return states; } -std::set<alphabet::Symbol> AutomatonFromXMLParser::parseInputAlphabet(std::list<sax::Token> &input) { +std::set<alphabet::Symbol> AutomatonFromXMLParser::parseInputAlphabet(std::list<sax::Token> &input) const { std::set<alphabet::Symbol> inputSymbols; popToken(input, sax::Token::START_ELEMENT, "inputAlphabet"); while (isTokenType(input, sax::Token::START_ELEMENT)) { @@ -149,14 +149,14 @@ std::set<alphabet::Symbol> AutomatonFromXMLParser::parseInputAlphabet(std::list< return inputSymbols; } -State AutomatonFromXMLParser::parseInitialState(std::list<sax::Token> &input) { +State AutomatonFromXMLParser::parseInitialState(std::list<sax::Token> &input) const { popToken(input, sax::Token::START_ELEMENT, "initialState"); State state = State(parseLabel(input)); popToken(input, sax::Token::END_ELEMENT, "initialState"); return state; } -std::set<State> AutomatonFromXMLParser::parseInitialStates(std::list<sax::Token> &input) { +std::set<State> AutomatonFromXMLParser::parseInitialStates(std::list<sax::Token> &input) const { std::set<State> initialStates; popToken(input, sax::Token::START_ELEMENT, "initialStates"); while (isTokenType(input, sax::Token::START_ELEMENT)) { @@ -168,7 +168,7 @@ std::set<State> AutomatonFromXMLParser::parseInitialStates(std::list<sax::Token> return initialStates; } -std::set<State> AutomatonFromXMLParser::parseFinalStates(std::list<sax::Token> &input) { +std::set<State> AutomatonFromXMLParser::parseFinalStates(std::list<sax::Token> &input) const { std::set<State> finalStates; popToken(input, sax::Token::START_ELEMENT, "finalStates"); while (isTokenType(input, sax::Token::START_ELEMENT)) { @@ -180,7 +180,7 @@ std::set<State> AutomatonFromXMLParser::parseFinalStates(std::list<sax::Token> & return finalStates; } -std::set<alphabet::Symbol> AutomatonFromXMLParser::parseStackAlphabet(std::list<sax::Token> &input) { +std::set<alphabet::Symbol> AutomatonFromXMLParser::parseStackAlphabet(std::list<sax::Token> &input) const { std::set<alphabet::Symbol> stackSymbols; popToken(input, sax::Token::START_ELEMENT, "stackAlphabet"); while (isTokenType(input, sax::Token::START_ELEMENT)) { @@ -192,7 +192,7 @@ std::set<alphabet::Symbol> AutomatonFromXMLParser::parseStackAlphabet(std::list< return stackSymbols; } -std::set<alphabet::Symbol> AutomatonFromXMLParser::parseInitialSymbols(std::list<sax::Token> &input) { +std::set<alphabet::Symbol> AutomatonFromXMLParser::parseInitialSymbols(std::list<sax::Token> &input) const { std::set<alphabet::Symbol> initialSymbols; popToken(input, sax::Token::START_ELEMENT, "initialAlphabet"); while (isTokenType(input, sax::Token::START_ELEMENT)) { @@ -204,7 +204,7 @@ std::set<alphabet::Symbol> AutomatonFromXMLParser::parseInitialSymbols(std::list return initialSymbols; } -std::set<alphabet::Symbol> AutomatonFromXMLParser::parseTapeAlphabet(std::list<sax::Token> &input) { +std::set<alphabet::Symbol> AutomatonFromXMLParser::parseTapeAlphabet(std::list<sax::Token> &input) const { std::set<alphabet::Symbol> tapeSymbols; popToken(input, sax::Token::START_ELEMENT, "tapeAlphabet"); while (isTokenType(input, sax::Token::START_ELEMENT)) { @@ -216,7 +216,7 @@ std::set<alphabet::Symbol> AutomatonFromXMLParser::parseTapeAlphabet(std::list<s return tapeSymbols; } -alphabet::Symbol AutomatonFromXMLParser::parseBlankSymbol(std::list<sax::Token>& input) { +alphabet::Symbol AutomatonFromXMLParser::parseBlankSymbol(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "blankSymbol"); alphabet::Symbol result = alphabet::Symbol(alphabet::BlankSymbol()); @@ -233,7 +233,7 @@ alphabet::Symbol AutomatonFromXMLParser::parseBlankSymbol(std::list<sax::Token>& } template<class T> -void AutomatonFromXMLParser::parseTransitions(std::list<sax::Token> &input, T& automaton) { +void AutomatonFromXMLParser::parseTransitions(std::list<sax::Token> &input, T& automaton) const { popToken(input, sax::Token::START_ELEMENT, "transitions"); while (isTokenType(input, sax::Token::START_ELEMENT)) { popToken(input, sax::Token::START_ELEMENT, "transition"); @@ -243,7 +243,7 @@ void AutomatonFromXMLParser::parseTransitions(std::list<sax::Token> &input, T& a popToken(input, sax::Token::END_ELEMENT, "transitions"); } -void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, DFA& automaton) { +void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, DFA& automaton) const { State from = parseTransitionFrom(input); alphabet::Symbol inputSymbol = parseTransitionInputSymbol(input); State to = parseTransitionTo(input); @@ -251,7 +251,7 @@ void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, DFA& automaton.addTransition(from, inputSymbol, to); } -void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, NFA& automaton) { +void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, NFA& automaton) const { State from = parseTransitionFrom(input); alphabet::Symbol inputSymbol = parseTransitionInputSymbol(input); State to = parseTransitionTo(input); @@ -259,7 +259,7 @@ void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, NFA& automaton.addTransition(from, inputSymbol, to); } -void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, EpsilonNFA& automaton) { +void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, EpsilonNFA& automaton) const { State from = parseTransitionFrom(input); std::variant<string::Epsilon, alphabet::Symbol> inputVariant = parseTransitionInputEpsilonSymbol(input); State to = parseTransitionTo(input); @@ -267,7 +267,7 @@ void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, Epsil automaton.addTransition(from, inputVariant, to); } -void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, UnknownAutomaton& automaton) { +void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, UnknownAutomaton& automaton) const { UnknownTransition transition; while (isTokenType(input, sax::Token::START_ELEMENT)) { @@ -293,21 +293,21 @@ void AutomatonFromXMLParser::parseTransition(std::list<sax::Token>& input, Unkno automaton.addTransition(transition); } -State AutomatonFromXMLParser::parseTransitionTo(std::list<sax::Token> &input) { +State AutomatonFromXMLParser::parseTransitionTo(std::list<sax::Token> &input) const { popToken(input, sax::Token::START_ELEMENT, "to"); State state(parseLabel(input)); popToken(input, sax::Token::END_ELEMENT, "to"); return state; } -State AutomatonFromXMLParser::parseTransitionFrom(std::list<sax::Token> &input) { +State AutomatonFromXMLParser::parseTransitionFrom(std::list<sax::Token> &input) const { popToken(input, sax::Token::START_ELEMENT, "from"); State state(parseLabel(input)); popToken(input, sax::Token::END_ELEMENT, "from"); return state; } -Shift AutomatonFromXMLParser::parseTransitionShift(std::list<sax::Token>& input) { +Shift AutomatonFromXMLParser::parseTransitionShift(std::list<sax::Token>& input) const { Shift shift; popToken(input, sax::Token::START_ELEMENT, "shift"); @@ -328,7 +328,7 @@ Shift AutomatonFromXMLParser::parseTransitionShift(std::list<sax::Token>& input) return shift; } -std::vector<alphabet::Symbol> AutomatonFromXMLParser::parseTransitionPop(std::list<sax::Token>& input) { +std::vector<alphabet::Symbol> AutomatonFromXMLParser::parseTransitionPop(std::list<sax::Token>& input) const { std::vector<alphabet::Symbol> pops; popToken(input, sax::Token::START_ELEMENT, "pop"); while (isTokenType(input, sax::Token::START_ELEMENT)) { @@ -340,7 +340,7 @@ std::vector<alphabet::Symbol> AutomatonFromXMLParser::parseTransitionPop(std::li return pops; } -std::vector<alphabet::Symbol> AutomatonFromXMLParser::parseTransitionPush(std::list<sax::Token>& input) { +std::vector<alphabet::Symbol> AutomatonFromXMLParser::parseTransitionPush(std::list<sax::Token>& input) const { std::vector<alphabet::Symbol> pushes; popToken(input, sax::Token::START_ELEMENT, "push"); while (isTokenType(input, sax::Token::START_ELEMENT)) { @@ -352,21 +352,21 @@ std::vector<alphabet::Symbol> AutomatonFromXMLParser::parseTransitionPush(std::l return pushes; } -alphabet::Symbol AutomatonFromXMLParser::parseTransitionOutputSymbol(std::list<sax::Token>& input) { +alphabet::Symbol AutomatonFromXMLParser::parseTransitionOutputSymbol(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "output"); alphabet::Symbol result = alphabet::Symbol(alphabet::LabeledSymbol(label::Label(label::StringLabel(parseLabel(input))))); popToken(input, sax::Token::END_ELEMENT, "output"); return result; } -alphabet::Symbol AutomatonFromXMLParser::parseTransitionInputSymbol(std::list<sax::Token>& input) { +alphabet::Symbol AutomatonFromXMLParser::parseTransitionInputSymbol(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "input"); alphabet::Symbol result = alphabet::Symbol(alphabet::LabeledSymbol(label::Label(label::StringLabel(parseLabel(input))))); popToken(input, sax::Token::END_ELEMENT, "input"); return result; } -std::variant<string::Epsilon, alphabet::Symbol> AutomatonFromXMLParser::parseTransitionInputEpsilonSymbol(std::list<sax::Token>& input) { +std::variant<string::Epsilon, alphabet::Symbol> AutomatonFromXMLParser::parseTransitionInputEpsilonSymbol(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "input"); std::variant<string::Epsilon, alphabet::Symbol> result; @@ -383,7 +383,7 @@ std::variant<string::Epsilon, alphabet::Symbol> AutomatonFromXMLParser::parseTra return result; } -std::variant<string::Epsilon, alphabet::Symbol> AutomatonFromXMLParser::parseTransitionOutputEpsilonSymbol(std::list<sax::Token>& input) { +std::variant<string::Epsilon, alphabet::Symbol> AutomatonFromXMLParser::parseTransitionOutputEpsilonSymbol(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "output"); std::variant<string::Epsilon, alphabet::Symbol> result; @@ -400,7 +400,7 @@ std::variant<string::Epsilon, alphabet::Symbol> AutomatonFromXMLParser::parseTra return result; } -std::variant<string::Epsilon, alphabet::Symbol> AutomatonFromXMLParser::parseTransitionInputBlankEpsilonSymbol(std::list<sax::Token>& input) { +std::variant<string::Epsilon, alphabet::Symbol> AutomatonFromXMLParser::parseTransitionInputBlankEpsilonSymbol(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "input"); std::variant<string::Epsilon, alphabet::Symbol> result; @@ -421,7 +421,7 @@ std::variant<string::Epsilon, alphabet::Symbol> AutomatonFromXMLParser::parseTra return result; } -std::variant<string::Epsilon, alphabet::Symbol> AutomatonFromXMLParser::parseTransitionOutputBlankEpsilonSymbol(std::list<sax::Token>& input) { +std::variant<string::Epsilon, alphabet::Symbol> AutomatonFromXMLParser::parseTransitionOutputBlankEpsilonSymbol(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "output"); std::variant<string::Epsilon, alphabet::Symbol> result; diff --git a/alib2/src/automaton/AutomatonFromXMLParser.h b/alib2/src/automaton/AutomatonFromXMLParser.h index 6487a9b2e679a72258d83ffd483f2bdb557acfe4..cda63235855f0de47dcec0c6d97b78bf77ed6e1b 100644 --- a/alib2/src/automaton/AutomatonFromXMLParser.h +++ b/alib2/src/automaton/AutomatonFromXMLParser.h @@ -27,40 +27,40 @@ namespace automaton { */ class AutomatonFromXMLParser : public sax::FromXMLParser { protected: - std::string parseLabel(std::list<sax::Token> &input); + std::string parseLabel(std::list<sax::Token> &input) const; - std::set<State> parseStates(std::list<sax::Token> &input); - std::set<alphabet::Symbol> parseInputAlphabet(std::list<sax::Token> &input); - std::set<alphabet::Symbol> parseStackAlphabet(std::list<sax::Token> &input); - std::set<alphabet::Symbol> parseInitialSymbols(std::list<sax::Token> &input); - std::set<alphabet::Symbol> parseTapeAlphabet(std::list<sax::Token> &input); - State parseInitialState(std::list<sax::Token> &input); - std::set<State> parseInitialStates(std::list<sax::Token> &input); - std::set<State> parseFinalStates(std::list<sax::Token> &input); - alphabet::Symbol parseBlankSymbol(std::list<sax::Token> &input); + std::set<State> parseStates(std::list<sax::Token> &input) const; + std::set<alphabet::Symbol> parseInputAlphabet(std::list<sax::Token> &input) const; + std::set<alphabet::Symbol> parseStackAlphabet(std::list<sax::Token> &input) const; + std::set<alphabet::Symbol> parseInitialSymbols(std::list<sax::Token> &input) const; + std::set<alphabet::Symbol> parseTapeAlphabet(std::list<sax::Token> &input) const; + State parseInitialState(std::list<sax::Token> &input) const; + std::set<State> parseInitialStates(std::list<sax::Token> &input) const; + std::set<State> parseFinalStates(std::list<sax::Token> &input) const; + alphabet::Symbol parseBlankSymbol(std::list<sax::Token> &input) const; - State parseTransitionFrom(std::list<sax::Token>& input); - State parseTransitionTo(std::list<sax::Token>& input); - Shift parseTransitionShift(std::list<sax::Token>& input); - std::vector<alphabet::Symbol> parseTransitionPop(std::list<sax::Token>& input); - std::vector<alphabet::Symbol> parseTransitionPush(std::list<sax::Token>& input); + State parseTransitionFrom(std::list<sax::Token>& input) const; + State parseTransitionTo(std::list<sax::Token>& input) const; + Shift parseTransitionShift(std::list<sax::Token>& input) const; + std::vector<alphabet::Symbol> parseTransitionPop(std::list<sax::Token>& input) const; + std::vector<alphabet::Symbol> parseTransitionPush(std::list<sax::Token>& input) const; template<class T> - void parseTransitions(std::list<sax::Token> &input, T& automaton); - void parseTransition(std::list<sax::Token>& input, UnknownAutomaton& automaton); - void parseTransition(std::list<sax::Token>& input, EpsilonNFA& automaton); - void parseTransition(std::list<sax::Token>& input, NFA& automaton); - void parseTransition(std::list<sax::Token>& input, DFA& automaton); + void parseTransitions(std::list<sax::Token> &input, T& automaton) const; + void parseTransition(std::list<sax::Token>& input, UnknownAutomaton& automaton) const; + void parseTransition(std::list<sax::Token>& input, EpsilonNFA& automaton) const; + void parseTransition(std::list<sax::Token>& input, NFA& automaton) const; + void parseTransition(std::list<sax::Token>& input, DFA& automaton) const; - alphabet::Symbol parseTransitionInputSymbol(std::list<sax::Token> &input); - std::variant<string::Epsilon, alphabet::Symbol> parseTransitionInputEpsilonSymbol(std::list<sax::Token> &input); - std::variant<string::Epsilon, alphabet::Symbol> parseTransitionInputBlankEpsilonSymbol(std::list<sax::Token> &input); - alphabet::Symbol parseTransitionOutputSymbol(std::list<sax::Token> &input); - std::variant<string::Epsilon, alphabet::Symbol> parseTransitionOutputEpsilonSymbol(std::list<sax::Token> &input); - std::variant<string::Epsilon, alphabet::Symbol> parseTransitionOutputBlankEpsilonSymbol(std::list<sax::Token> &input); + alphabet::Symbol parseTransitionInputSymbol(std::list<sax::Token> &input) const; + std::variant<string::Epsilon, alphabet::Symbol> parseTransitionInputEpsilonSymbol(std::list<sax::Token> &input) const; + std::variant<string::Epsilon, alphabet::Symbol> parseTransitionInputBlankEpsilonSymbol(std::list<sax::Token> &input) const; + alphabet::Symbol parseTransitionOutputSymbol(std::list<sax::Token> &input) const; + std::variant<string::Epsilon, alphabet::Symbol> parseTransitionOutputEpsilonSymbol(std::list<sax::Token> &input) const; + std::variant<string::Epsilon, alphabet::Symbol> parseTransitionOutputBlankEpsilonSymbol(std::list<sax::Token> &input) const; - alphabet::Symbol parseSymbolIO(std::list<sax::Token> &input); - std::variant<string::Epsilon, alphabet::Symbol> parseEpsilonSymbolIO(std::list<sax::Token> &input); + alphabet::Symbol parseSymbolIO(std::list<sax::Token> &input) const; + std::variant<string::Epsilon, alphabet::Symbol> parseEpsilonSymbolIO(std::list<sax::Token> &input) const; public: /** * Parses the xml and returns the automaton. The input is destroyed in the process. @@ -68,12 +68,12 @@ public: * @return UnknownAutomaton * @throws ParserException when an error occurs */ - Automaton parse(std::list<sax::Token> &input); + Automaton parse(std::list<sax::Token> &input) const; - UnknownAutomaton parseUnknownAutomaton(std::list<sax::Token>& input); - EpsilonNFA parseEpsilonNFA(std::list<sax::Token>& input); - NFA parseNFA(std::list<sax::Token>& input); - DFA parseDFA(std::list<sax::Token>& input); + UnknownAutomaton parseUnknownAutomaton(std::list<sax::Token>& input) const; + EpsilonNFA parseEpsilonNFA(std::list<sax::Token>& input) const; + NFA parseNFA(std::list<sax::Token>& input) const; + DFA parseDFA(std::list<sax::Token>& input) const; }; } /* namespace automaton */ diff --git a/alib2/src/factory/AutomatonFactory.cpp b/alib2/src/factory/AutomatonFactory.cpp index 7fcda1eec2cd8f70025fc3d241b3aa88c4537d1e..0a2c5b53641a351ee596c9a77b2fc876ae73aca5 100644 --- a/alib2/src/factory/AutomatonFactory.cpp +++ b/alib2/src/factory/AutomatonFactory.cpp @@ -11,6 +11,8 @@ #include "../sax/SaxComposeInterface.h" #include "../automaton/AutomatonFromXMLParser.h" #include "../automaton/AutomatonToXMLComposer.h" +#include "../FromXMLParsers.h" +#include "../ToXMLComposers.h" namespace automaton { @@ -36,8 +38,7 @@ Automaton AutomatonFactory::fromStream(std::istream& in) { } Automaton AutomatonFactory::parse(std::list<sax::Token> tokens) { - AutomatonFromXMLParser parser; - return parser.parse(tokens); + return alib::FromXMLParsers::automatonParser.parse(tokens); } void AutomatonFactory::toFile(const Automaton& automaton, const std::string& filename) { diff --git a/alib2/src/label/LabelFromXMLParser.cpp b/alib2/src/label/LabelFromXMLParser.cpp index 8b1f3c9e3f17bde89ccc4ecf8270e06fe6380971..fac86b18c0bdae7b41a5324cd80edfdeaa9e1969 100644 --- a/alib2/src/label/LabelFromXMLParser.cpp +++ b/alib2/src/label/LabelFromXMLParser.cpp @@ -13,7 +13,7 @@ namespace label { -Label LabelFromXMLParser::parse(std::list<sax::Token>& input) { +Label LabelFromXMLParser::parse(std::list<sax::Token>& input) const { if(isToken(input, sax::Token::START_ELEMENT, "IntegerLabel")) { popToken(input, sax::Token::START_ELEMENT, "IntegerLabel"); label::Label data = Label(IntegerLabel(std::stoi(popTokenData(input, sax::Token::CHARACTER)))); diff --git a/alib2/src/label/LabelFromXMLParser.h b/alib2/src/label/LabelFromXMLParser.h index b46cfbda870de67c3bc691c3079da316d8ff0cfb..2f5fa2b02d0196cdf7e8ce2d7fd9fe85ecc7e1ce 100644 --- a/alib2/src/label/LabelFromXMLParser.h +++ b/alib2/src/label/LabelFromXMLParser.h @@ -27,7 +27,7 @@ public: * @return String * @throws ParserException when an error occurs */ - Label parse(std::list<sax::Token>& input); + Label parse(std::list<sax::Token>& input) const; }; diff --git a/alib2/src/regexp/RegExpFromXMLParser.cpp b/alib2/src/regexp/RegExpFromXMLParser.cpp index 18509c833da7e52edec10d6e5b9d794f06377f20..4630885b8e7cc9f970399234c543581175ec1e0b 100644 --- a/alib2/src/regexp/RegExpFromXMLParser.cpp +++ b/alib2/src/regexp/RegExpFromXMLParser.cpp @@ -11,7 +11,7 @@ namespace regexp { -RegExp RegExpFromXMLParser::parse(std::list<sax::Token>& input) { +RegExp RegExpFromXMLParser::parse(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "regexp"); RegExp regexp; @@ -28,7 +28,7 @@ RegExp RegExpFromXMLParser::parse(std::list<sax::Token>& input) { return regexp; } -void RegExpFromXMLParser::parseAlphabet(std::list<sax::Token> &input, RegExp& regexp) { +void RegExpFromXMLParser::parseAlphabet(std::list<sax::Token> &input, RegExp& regexp) const { popToken(input, sax::Token::START_ELEMENT, "alphabet"); while (isToken(input, sax::Token::START_ELEMENT, "symbol")) { alphabet::Symbol* symbol = parseSymbol<alphabet::Symbol>(input); @@ -38,7 +38,7 @@ void RegExpFromXMLParser::parseAlphabet(std::list<sax::Token> &input, RegExp& re popToken(input, sax::Token::END_ELEMENT, "alphabet"); } -RegExpElement* RegExpFromXMLParser::parseElement(std::list<sax::Token>& input) { +RegExpElement* RegExpFromXMLParser::parseElement(std::list<sax::Token>& input) const { if (isToken(input, sax::Token::START_ELEMENT, "symbol")) { return parseSymbol<RegExpSymbol>(input); } else if (isToken(input, sax::Token::START_ELEMENT, "empty")) { @@ -56,7 +56,7 @@ RegExpElement* RegExpFromXMLParser::parseElement(std::list<sax::Token>& input) { } } -Alternation* RegExpFromXMLParser::parseAlternation(std::list<sax::Token>& input) { +Alternation* RegExpFromXMLParser::parseAlternation(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "alternation"); RegExpElement* element1 = parseElement(input); @@ -78,7 +78,7 @@ Alternation* RegExpFromXMLParser::parseAlternation(std::list<sax::Token>& input) return alternation; } -Concatenation* RegExpFromXMLParser::parseConcatenation(std::list<sax::Token>& input) { +Concatenation* RegExpFromXMLParser::parseConcatenation(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "concatenation"); RegExpElement* element1 = parseElement(input); @@ -101,7 +101,7 @@ Concatenation* RegExpFromXMLParser::parseConcatenation(std::list<sax::Token>& in } -Iteration* RegExpFromXMLParser::parseIteration(std::list<sax::Token>& input) { +Iteration* RegExpFromXMLParser::parseIteration(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "iteration"); RegExpElement* element = parseElement(input); @@ -113,7 +113,7 @@ Iteration* RegExpFromXMLParser::parseIteration(std::list<sax::Token>& input) { return iteration; } -RegExpEpsilon* RegExpFromXMLParser::parseEpsilon(std::list<sax::Token>& input) { +RegExpEpsilon* RegExpFromXMLParser::parseEpsilon(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "epsilon"); RegExpEpsilon* epsilon = new RegExpEpsilon(); @@ -122,7 +122,7 @@ RegExpEpsilon* RegExpFromXMLParser::parseEpsilon(std::list<sax::Token>& input) { return epsilon; } -RegExpEmpty* RegExpFromXMLParser::parseEmpty(std::list<sax::Token>& input) { +RegExpEmpty* RegExpFromXMLParser::parseEmpty(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "empty"); RegExpEmpty* empty = new RegExpEmpty(); @@ -132,7 +132,7 @@ RegExpEmpty* RegExpFromXMLParser::parseEmpty(std::list<sax::Token>& input) { } template <class T> -T* RegExpFromXMLParser::parseSymbol(std::list<sax::Token>& input) { +T* RegExpFromXMLParser::parseSymbol(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "symbol"); T* symbol = new T(alphabet::Symbol(alphabet::LabeledSymbol(label::Label(label::StringLabel(popTokenData(input, sax::Token::CHARACTER)))))); diff --git a/alib2/src/regexp/RegExpFromXMLParser.h b/alib2/src/regexp/RegExpFromXMLParser.h index f1d29032034747163afc8241545d62a1065a8dc8..d5097dbe022e6c2018fe34e6d64c27d9a108a477 100644 --- a/alib2/src/regexp/RegExpFromXMLParser.h +++ b/alib2/src/regexp/RegExpFromXMLParser.h @@ -20,16 +20,16 @@ namespace regexp { * Parser used to get RegExp from XML parsed into list of tokens. */ class RegExpFromXMLParser : public sax::FromXMLParser { - void parseAlphabet(std::list<sax::Token>& input, RegExp& regexp); + void parseAlphabet(std::list<sax::Token>& input, RegExp& regexp) const; - RegExpElement* parseElement(std::list<sax::Token>& input); + RegExpElement* parseElement(std::list<sax::Token>& input) const; - RegExpEpsilon* parseEpsilon(std::list<sax::Token>& input); - RegExpEmpty* parseEmpty(std::list<sax::Token>& input); - template <class T> T* parseSymbol(std::list<sax::Token> &input); - Iteration* parseIteration(std::list<sax::Token> &input); - Alternation* parseAlternation(std::list<sax::Token> &input); - Concatenation* parseConcatenation(std::list<sax::Token> &input); + RegExpEpsilon* parseEpsilon(std::list<sax::Token>& input) const; + RegExpEmpty* parseEmpty(std::list<sax::Token>& input) const; + template <class T> T* parseSymbol(std::list<sax::Token> &input) const; + Iteration* parseIteration(std::list<sax::Token> &input) const; + Alternation* parseAlternation(std::list<sax::Token> &input) const; + Concatenation* parseConcatenation(std::list<sax::Token> &input) const; public: /** @@ -38,7 +38,7 @@ public: * @return RegExp * @throws ParserException when an error occurs */ - RegExp parse(std::list<sax::Token>& input); + RegExp parse(std::list<sax::Token>& input) const; }; } /* namespace regexp */ diff --git a/alib2/src/sax/FromXMLParser.cpp b/alib2/src/sax/FromXMLParser.cpp index 0f6c6e76b6a7810f5ef3d496ee32eb53cb4c4d98..c60ce1b174eafab9747393d85a2d410e686ca53a 100644 --- a/alib2/src/sax/FromXMLParser.cpp +++ b/alib2/src/sax/FromXMLParser.cpp @@ -10,15 +10,15 @@ namespace sax { -bool FromXMLParser::isToken(std::list<Token>& input, Token::TokenType type, std::string data) { +bool FromXMLParser::isToken(std::list<Token>& input, Token::TokenType type, std::string data) const { return input.front().getType() == type && input.front().getData() == data; } -bool FromXMLParser::isTokenType(std::list<Token>& input, Token::TokenType type) { +bool FromXMLParser::isTokenType(std::list<Token>& input, Token::TokenType type) const { return input.front().getType() == type; } -void FromXMLParser::popToken(std::list<Token>& input, Token::TokenType type, std::string data) { +void FromXMLParser::popToken(std::list<Token>& input, Token::TokenType type, std::string data) const { if (isToken(input, type, data)) { input.pop_front(); } else { @@ -26,7 +26,7 @@ void FromXMLParser::popToken(std::list<Token>& input, Token::TokenType type, std } } -std::string FromXMLParser::popTokenData(std::list<Token>& input, Token::TokenType type) { +std::string FromXMLParser::popTokenData(std::list<Token>& input, Token::TokenType type) const { if(isTokenType(input, type)) { std::string result = input.front().getData(); input.pop_front(); diff --git a/alib2/src/sax/FromXMLParser.h b/alib2/src/sax/FromXMLParser.h index c6f3c6c20ad1625d077c8c667aff437a81f1aca4..67b65c17f1d4f48aff902a8624b2cb067562cea6 100644 --- a/alib2/src/sax/FromXMLParser.h +++ b/alib2/src/sax/FromXMLParser.h @@ -18,10 +18,10 @@ namespace sax { */ class FromXMLParser { protected: - bool isToken(std::list<Token> &input, Token::TokenType type, std::string data); - bool isTokenType(std::list<Token>& input, Token::TokenType type); - void popToken(std::list<Token> &input, Token::TokenType type, std::string data); - std::string popTokenData(std::list<Token>& input, Token::TokenType type); + bool isToken(std::list<Token> &input, Token::TokenType type, std::string data) const; + bool isTokenType(std::list<Token>& input, Token::TokenType type) const; + void popToken(std::list<Token> &input, Token::TokenType type, std::string data) const; + std::string popTokenData(std::list<Token>& input, Token::TokenType type) const; }; diff --git a/alib2/src/string/StringFromXMLParser.cpp b/alib2/src/string/StringFromXMLParser.cpp index e254d946f96b2deefb939573c79fcbd819321fe7..eea77b26d867e8d0164770633acd4d747a479b3d 100644 --- a/alib2/src/string/StringFromXMLParser.cpp +++ b/alib2/src/string/StringFromXMLParser.cpp @@ -16,7 +16,7 @@ namespace string { -String StringFromXMLParser::parse(std::list<sax::Token>& input) { +String StringFromXMLParser::parse(std::list<sax::Token>& input) const { if(isToken(input, sax::Token::START_ELEMENT, "Epsilon")) { popToken(input, sax::Token::START_ELEMENT, "Epsilon"); popToken(input, sax::Token::END_ELEMENT, "Epsilon"); @@ -36,7 +36,7 @@ String StringFromXMLParser::parse(std::list<sax::Token>& input) { } } -std::vector<alphabet::Symbol> StringFromXMLParser::parseContent(std::list<sax::Token>& input) { +std::vector<alphabet::Symbol> StringFromXMLParser::parseContent(std::list<sax::Token>& input) const { std::vector<alphabet::Symbol> data; while (isToken(input, sax::Token::START_ELEMENT, "Symbol")) { data.push_back(parseSymbol(input)); @@ -44,7 +44,7 @@ std::vector<alphabet::Symbol> StringFromXMLParser::parseContent(std::list<sax::T return data; } -alphabet::Symbol StringFromXMLParser::parseSymbol(std::list<sax::Token>& input) { +alphabet::Symbol StringFromXMLParser::parseSymbol(std::list<sax::Token>& input) const { popToken(input, sax::Token::START_ELEMENT, "Symbol"); if (input.front().getType() == sax::Token::CHARACTER) { diff --git a/alib2/src/string/StringFromXMLParser.h b/alib2/src/string/StringFromXMLParser.h index da782c79b5305fdee09fd1f5406dce6ef9f15ff8..6eccc37f4c992edb5db942ccbee88e8ef0b0b9f8 100644 --- a/alib2/src/string/StringFromXMLParser.h +++ b/alib2/src/string/StringFromXMLParser.h @@ -20,8 +20,8 @@ namespace string { * Parser used to get String from XML parsed into list of tokens. */ class StringFromXMLParser : public sax::FromXMLParser { - std::vector<alphabet::Symbol> parseContent(std::list<sax::Token>& input); - alphabet::Symbol parseSymbol(std::list<sax::Token>& input); + std::vector<alphabet::Symbol> parseContent(std::list<sax::Token>& input) const; + alphabet::Symbol parseSymbol(std::list<sax::Token>& input) const; public: /** @@ -30,7 +30,7 @@ public: * @return String * @throws ParserException when an error occurs */ - String parse(std::list<sax::Token>& input); + String parse(std::list<sax::Token>& input) const; };