From cb671b36ebcd751501535e08a1547c79dafb825c Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 30 Sep 2014 19:01:05 +0200 Subject: [PATCH] NFA DFA stats --- astat2/src/AutomataStat.cpp | 134 ++++++++++++++++++++++++++++++++++++ astat2/src/astat.cpp | 54 ++++++++++++++- 2 files changed, 185 insertions(+), 3 deletions(-) diff --git a/astat2/src/AutomataStat.cpp b/astat2/src/AutomataStat.cpp index e023eb4501..feedb1e678 100644 --- a/astat2/src/AutomataStat.cpp +++ b/astat2/src/AutomataStat.cpp @@ -33,9 +33,143 @@ void AutomataStat::stat(const automaton::NFA& automaton, const Settings& setting case PrintOptions::NOOP: break; } + + switch(settings.finalStates) { + case PrintOptions::PRINT: + alib::DataFactory::toStdout(automaton.getFinalStates()); + break; + case PrintOptions::QUANTITY: + std::cout << automaton.getFinalStates().size() << std::endl; + break; + case PrintOptions::BOTH: + std::cout << automaton.getFinalStates().size() << std::endl; + alib::DataFactory::toStdout(automaton.getFinalStates()); + break; + case PrintOptions::NOOP: + break; + } + + switch(settings.initialStates) { + case PrintOptions::PRINT: + alib::DataFactory::toStdout(automaton.getInitialStates()); + break; + case PrintOptions::QUANTITY: + std::cout << automaton.getInitialStates().size() << std::endl; + break; + case PrintOptions::BOTH: + std::cout << automaton.getInitialStates().size() << std::endl; + alib::DataFactory::toStdout(automaton.getInitialStates()); + break; + case PrintOptions::NOOP: + break; + } + + switch(settings.alphabet) { + case PrintOptions::PRINT: + alib::DataFactory::toStdout(automaton.getInputAlphabet()); + break; + case PrintOptions::QUANTITY: + std::cout << automaton.getInputAlphabet().size() << std::endl; + break; + case PrintOptions::BOTH: + std::cout << automaton.getInputAlphabet().size() << std::endl; + alib::DataFactory::toStdout(automaton.getInputAlphabet()); + break; + case PrintOptions::NOOP: + break; + } + + switch(settings.transitions) { + case PrintOptions::PRINT: + alib::DataFactory::toStdout(automaton.getTransitions()); + break; + case PrintOptions::QUANTITY: + std::cout << automaton.getTransitions().size() << std::endl; + break; + case PrintOptions::BOTH: + std::cout << automaton.getTransitions().size() << std::endl; + alib::DataFactory::toStdout(automaton.getTransitions()); + break; + case PrintOptions::NOOP: + break; + } } void AutomataStat::stat(const automaton::DFA& automaton, const Settings& settings) { + switch(settings.states) { + case PrintOptions::PRINT: + alib::DataFactory::toStdout(automaton.getStates()); + break; + case PrintOptions::QUANTITY: + std::cout << automaton.getStates().size() << std::endl; + break; + case PrintOptions::BOTH: + std::cout << automaton.getStates().size() << std::endl; + alib::DataFactory::toStdout(automaton.getStates()); + break; + case PrintOptions::NOOP: + break; + } + + switch(settings.finalStates) { + case PrintOptions::PRINT: + alib::DataFactory::toStdout(automaton.getFinalStates()); + break; + case PrintOptions::QUANTITY: + std::cout << automaton.getFinalStates().size() << std::endl; + break; + case PrintOptions::BOTH: + std::cout << automaton.getFinalStates().size() << std::endl; + alib::DataFactory::toStdout(automaton.getFinalStates()); + break; + case PrintOptions::NOOP: + break; + } + + switch(settings.initialStates) { + case PrintOptions::PRINT: + alib::DataFactory::toStdout(automaton.getInitialState()); + break; + case PrintOptions::QUANTITY: + std::cout << 1 << std::endl; + break; + case PrintOptions::BOTH: + std::cout << 1 << std::endl; + alib::DataFactory::toStdout(automaton.getInitialState()); + break; + case PrintOptions::NOOP: + break; + } + + switch(settings.alphabet) { + case PrintOptions::PRINT: + alib::DataFactory::toStdout(automaton.getInputAlphabet()); + break; + case PrintOptions::QUANTITY: + std::cout << automaton.getInputAlphabet().size() << std::endl; + break; + case PrintOptions::BOTH: + std::cout << automaton.getInputAlphabet().size() << std::endl; + alib::DataFactory::toStdout(automaton.getInputAlphabet()); + break; + case PrintOptions::NOOP: + break; + } + + switch(settings.transitions) { + case PrintOptions::PRINT: + alib::DataFactory::toStdout(automaton.getTransitions()); + break; + case PrintOptions::QUANTITY: + std::cout << automaton.getTransitions().size() << std::endl; + break; + case PrintOptions::BOTH: + std::cout << automaton.getTransitions().size() << std::endl; + alib::DataFactory::toStdout(automaton.getTransitions()); + break; + case PrintOptions::NOOP: + break; + } } void AutomataStat::Visit(void*, const automaton::UnknownAutomaton&) const { diff --git a/astat2/src/astat.cpp b/astat2/src/astat.cpp index f866469739..bab80d56dc 100644 --- a/astat2/src/astat.cpp +++ b/astat2/src/astat.cpp @@ -29,7 +29,7 @@ int main(int argc, char* argv[]) { TCLAP::ValueArg<std::string> transitions( "t", "transitions", "Print or display number of transitions", false, "noop", &allowedVals); cmd.add(transitions); - TCLAP::UnlabeledValueArg<std::string> file( "file", "Read from file", false, "-", "file"); + TCLAP::UnlabeledValueArg<std::string> file( "file", "Read from file", false, "-", "file"); cmd.add( file ); cmd.parse(argc,argv); @@ -48,11 +48,59 @@ int main(int argc, char* argv[]) { } } + if(finalStates.isSet()) { + if(finalStates.getValue() == "noop") { + settings.finalStates = PrintOptions::NOOP; + } else if(finalStates.getValue() == "print") { + settings.finalStates = PrintOptions::PRINT; + } else if(finalStates.getValue() == "quantity") { + settings.finalStates = PrintOptions::QUANTITY; + } else if(finalStates.getValue() == "both") { + settings.finalStates = PrintOptions::BOTH; + } + } + + if(initialStates.isSet()) { + if(initialStates.getValue() == "noop") { + settings.initialStates = PrintOptions::NOOP; + } else if(initialStates.getValue() == "print") { + settings.initialStates = PrintOptions::PRINT; + } else if(initialStates.getValue() == "quantity") { + settings.initialStates = PrintOptions::QUANTITY; + } else if(initialStates.getValue() == "both") { + settings.initialStates = PrintOptions::BOTH; + } + } + + if(alphabet.isSet()) { + if(alphabet.getValue() == "noop") { + settings.alphabet = PrintOptions::NOOP; + } else if(alphabet.getValue() == "print") { + settings.alphabet = PrintOptions::PRINT; + } else if(alphabet.getValue() == "quantity") { + settings.alphabet = PrintOptions::QUANTITY; + } else if(alphabet.getValue() == "both") { + settings.alphabet = PrintOptions::BOTH; + } + } + + if(transitions.isSet()) { + if(transitions.getValue() == "noop") { + settings.transitions = PrintOptions::NOOP; + } else if(transitions.getValue() == "print") { + settings.transitions = PrintOptions::PRINT; + } else if(transitions.getValue() == "quantity") { + settings.transitions = PrintOptions::QUANTITY; + } else if(transitions.getValue() == "both") { + settings.transitions = PrintOptions::BOTH; + } + } + std::list<sax::Token> tokens; if(file.isSet()) { - sax::SaxParseInterface::parseStdin(tokens); - } else { sax::SaxParseInterface::parseFile(file.getValue(), tokens); + } else { + sax::SaxParseInterface::parseStdin(tokens); } if( alib::FromXMLParsers::automatonParser.first(tokens)) { -- GitLab