Skip to content
Snippets Groups Projects
Commit 26139eaa authored by Martin Žák's avatar Martin Žák
Browse files

acat, aconvert.* updates

parent a0c22b98
No related branches found
No related tags found
No related merge requests found
...@@ -6,22 +6,22 @@ ...@@ -6,22 +6,22 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <set> #include <set>
#include <cstdlib>
#include <unistd.h>
#include <exception>
#include "AutomatonFactory.h" #include "AutomatonFactory.h"
#include "GrammarFactory.h" #include "GrammarFactory.h"
#include "AlibException.h" #include "AlibException.h"
#include "regexp/RegExpParser.h" #include "regexp/RegExpParser.h"
#include "automaton/AutomatonParser.h" #include "automaton/AutomatonParser.h"
#include "grammar/GrammarParser.h" #include "grammar/GrammarParser.h"
#include "grammar/RightRegularGrammar.h" #include "grammar/RightRegularGrammar.h"
#include "sax/SaxInterface.h" #include "sax/SaxInterface.h"
#include "sax/ParserException.h" #include "sax/ParserException.h"
   
#include <exception>
#define VERSION "0.0.1"
#define USAGE "Usage: catPDA [-c] [input]";
   
using namespace std; using namespace std;
using namespace automaton; using namespace automaton;
...@@ -52,51 +52,43 @@ void getRegExp(list<Token>& tokens) { ...@@ -52,51 +52,43 @@ void getRegExp(list<Token>& tokens) {
} }
   
int main(int argc, char** argv) { int main(int argc, char** argv) {
if(argc == 2 && string(argv[1])=="-v" ) {
int fileParameterIndex = -1; cout << argv[0] << " version " << VERSION << "\n";
bool complexTypes = false; cout << USAGE;
cout << endl;
try { return EXIT_SUCCESS;
if (argc > 1) {
for (int i = 1; i < argc; i++) {
if (string("-h").compare(argv[i]) == 0) {
cout << "Automaton parsing.\nUsage: catPDA [automaton.xml]\n";
return -1;
} else if (string("-c").compare(argv[i]) == 0) {
complexTypes = true;
} else {
if(fileParameterIndex == -1) {
fileParameterIndex = i;
} else {
throw AlibException("Only one file can be passed as parameter - " + string(argv[i]) + " " + string(argv[fileParameterIndex]));
}
}
}
}
list<Token> tokens;
if(fileParameterIndex != -1) {
SaxInterface::parseFile(argv[fileParameterIndex],tokens);
} else {
string input(istreambuf_iterator<char>(cin), (istreambuf_iterator<char>()));
SaxInterface::parseMemory(input, tokens);
} }
   
if (tokens.front().getData() == "automaton") { bool concrete = false;
getAutomaton(tokens, complexTypes);
} else if (tokens.front().getData() == "grammar") { int i=getopt(argc, argv, "t:");
getGrammar(tokens); while(i!=-1) {
} else if (tokens.front().getData() == "regexp") { switch(i){
getRegExp(tokens); case 'c':
} else { concrete = true;
throw AlibException("Expected root tag automaton, grammar or regexp. Read: " + tokens.front().getData()); break;
default:
optind--;
break;
} }
i=getopt(argc, argv, "t:");
}
   
} catch (AlibException& e) { list<Token> tokens;
cout << e.what() << endl; if(optind == argc) {
return -1; string input(istreambuf_iterator<char>(cin), (istreambuf_iterator<char>()));
SaxInterface::parseMemory(input, tokens);
} else {
SaxInterface::parseFile(argv[optind],tokens);
} }
   
cout.flush(); if (tokens.front().getData() == "automaton") {
getAutomaton(tokens, concrete);
} else if (tokens.front().getData() == "grammar") {
getGrammar(tokens);
} else if (tokens.front().getData() == "regexp") {
getRegExp(tokens);
} else {
throw AlibException( "Expected root tag automaton, grammar or regexp. Read: " + tokens.front().getData());
}
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* DotConverter.cpp * DotConverter.cpp
* *
* Created on: Apr 1, 2013 * Created on: Apr 1, 2013
* Author: martin * Author: Martin Zak
*/ */
   
#include "DotConverter.h" #include "DotConverter.h"
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
using namespace std; using namespace std;
using namespace automaton; using namespace automaton;
   
void DotConverter::convert(const automaton::Automaton& a, std::ostream& out) { void DotConverter::convert(const Automaton& a, ostream& out) {
out << "digraph automaton {\n"; out << "digraph automaton {\n";
out << "rankdir=LR;\n"; out << "rankdir=LR;\n";
int cnt = 1; int cnt = 1;
...@@ -55,7 +55,7 @@ void DotConverter::convert(const automaton::Automaton& a, std::ostream& out) { ...@@ -55,7 +55,7 @@ void DotConverter::convert(const automaton::Automaton& a, std::ostream& out) {
transitions(fsm, states, out); transitions(fsm, states, out);
out << "}"; out << "}";
return; return;
} catch (const std::bad_cast& e) { } catch (const bad_cast& e) {
} }
   
try { try {
...@@ -63,7 +63,7 @@ void DotConverter::convert(const automaton::Automaton& a, std::ostream& out) { ...@@ -63,7 +63,7 @@ void DotConverter::convert(const automaton::Automaton& a, std::ostream& out) {
transitions(pda, states, out); transitions(pda, states, out);
out << "}"; out << "}";
return; return;
} catch (const std::bad_cast& e) { } catch (const bad_cast& e) {
} }
   
try { try {
...@@ -71,19 +71,19 @@ void DotConverter::convert(const automaton::Automaton& a, std::ostream& out) { ...@@ -71,19 +71,19 @@ void DotConverter::convert(const automaton::Automaton& a, std::ostream& out) {
transitions(tm, states, out); transitions(tm, states, out);
out << "}"; out << "}";
return; return;
} catch (const std::bad_cast& e) { } catch (const bad_cast& e) {
} }
   
} }
   
void DotConverter::transitions(const automaton::FSM& fsm, const std::map<automaton::State, int>& states, void DotConverter::transitions(const FSM& fsm, const map<State, int>& states,
std::ostream& out) { ostream& out) {
   
map<pair<int, int>, string> transitions; map<pair<int, int>, string> transitions;
const set<automaton::TransitionFSM>& t = fsm.getTransitions(); const set<TransitionFSM>& t = fsm.getTransitions();
   
//put transitions from automaton to "transitions" //put transitions from automaton to "transitions"
set<automaton::TransitionFSM>::const_iterator it = t.begin(); set<TransitionFSM>::const_iterator it = t.begin();
while (it != t.end()) { while (it != t.end()) {
string symbol; string symbol;
if (it->getInput().getSymbol().compare("") == 0) { if (it->getInput().getSymbol().compare("") == 0) {
...@@ -112,13 +112,13 @@ void DotConverter::transitions(const automaton::FSM& fsm, const std::map<automat ...@@ -112,13 +112,13 @@ void DotConverter::transitions(const automaton::FSM& fsm, const std::map<automat
it2++; it2++;
} }
} }
void DotConverter::transitions(const automaton::PDA& pda, const std::map<automaton::State, int>& states, void DotConverter::transitions(const PDA& pda, const map<State, int>& states,
std::ostream& out) { ostream& out) {
map<pair<int, int>, string> transitions; map<pair<int, int>, string> transitions;
const set<automaton::TransitionPDA>& t = pda.getTransitions(); const set<TransitionPDA>& t = pda.getTransitions();
   
//put transitions from automaton to "transitions" //put transitions from automaton to "transitions"
set<automaton::TransitionPDA>::const_iterator it = t.begin(); set<TransitionPDA>::const_iterator it = t.begin();
while (it != t.end()) { while (it != t.end()) {
string symbol; string symbol;
   
...@@ -175,13 +175,13 @@ void DotConverter::transitions(const automaton::PDA& pda, const std::map<automat ...@@ -175,13 +175,13 @@ void DotConverter::transitions(const automaton::PDA& pda, const std::map<automat
} }
} }
   
void DotConverter::transitions(const automaton::TM& tm, const std::map<automaton::State, int>& states, void DotConverter::transitions(const TM& tm, const map<State, int>& states,
std::ostream& out) { ostream& out) {
map<pair<int, int>, string> transitions; map<pair<int, int>, string> transitions;
const set<automaton::TransitionTM>& t = tm.getTransitions(); const set<TransitionTM>& t = tm.getTransitions();
   
//put transitions from automaton to "transitions" //put transitions from automaton to "transitions"
set<automaton::TransitionTM>::const_iterator it = t.begin(); set<TransitionTM>::const_iterator it = t.begin();
while (it != t.end()) { while (it != t.end()) {
string symbol; string symbol;
   
...@@ -190,7 +190,7 @@ void DotConverter::transitions(const automaton::TM& tm, const std::map<automaton ...@@ -190,7 +190,7 @@ void DotConverter::transitions(const automaton::TM& tm, const std::map<automaton
symbol += "/"; symbol += "/";
symbol += it->getOutput().getSymbol(); symbol += it->getOutput().getSymbol();
symbol += " "; symbol += " ";
symbol += (std::string[] ) { "&larr;", "&rarr;", "&times;" } [it->getShift()]; symbol += (string[] ) { "&larr;", "&rarr;", "&times;" } [it->getShift()];
   
//Insert into map //Insert into map
pair<int, int> key(states.find(it->getFrom())->second, states.find(it->getTo())->second); pair<int, int> key(states.find(it->getFrom())->second, states.find(it->getTo())->second);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* DotConverter.h * DotConverter.h
* *
* Created on: Apr 1, 2013 * Created on: Apr 1, 2013
* Author: martin * Author: Martin Zak
*/ */
   
#ifndef DOTCONVERTER_H_ #ifndef DOTCONVERTER_H_
...@@ -16,13 +16,16 @@ ...@@ -16,13 +16,16 @@
#include <map> #include <map>
#include <utility> #include <utility>
   
using namespace std;
using namespace automaton;
class DotConverter { class DotConverter {
protected: protected:
static void transitions(const automaton::FSM& fsm, const std::map<automaton::State, int>& states, std::ostream& out); static void transitions(const FSM& fsm, const map<State, int>& states, ostream& out);
static void transitions(const automaton::PDA& pda, const std::map<automaton::State, int>& states, std::ostream& out); static void transitions(const PDA& pda, const map<State, int>& states, ostream& out);
static void transitions(const automaton::TM& tm, const std::map<automaton::State, int>& states, std::ostream& out); static void transitions(const TM& tm, const map<State, int>& states, ostream& out);
public: public:
static void convert(const automaton::Automaton& a, std::ostream& out); static void convert(const Automaton& a, ostream& out);
}; };
   
#endif /* DOTCONVERTER_H_ */ #endif /* DOTCONVERTER_H_ */
//============================================================================ //============================================================================
// Name : aconverter.dot.cpp // Name : aconvert.dot.cpp
// Author : Martin Zak // Author : Martin Zak
//============================================================================ //============================================================================
   
#include <iostream> #include <iostream>
#include "automaton/AutomatonParser.h" #include "automaton/AutomatonParser.h"
#include "automaton/UnknownAutomaton.h" #include "automaton/UnknownAutomaton.h"
#include "AutomatonFactory.h" #include "AutomatonFactory.h"
...@@ -13,6 +12,9 @@ ...@@ -13,6 +12,9 @@
   
#include "DotConverter.h" #include "DotConverter.h"
   
#define VERSION "0.0.1"
#define USAGE "aconvert.dot [inputfile]"
using namespace std; using namespace std;
using namespace automaton; using namespace automaton;
using namespace sax; using namespace sax;
...@@ -20,28 +22,22 @@ using namespace alib; ...@@ -20,28 +22,22 @@ using namespace alib;
   
int main(int argc, char** argv) { int main(int argc, char** argv) {
list<Token> tokens; list<Token> tokens;
try {
if (argc > 1) {
if (string("-h").compare(argv[1]) == 0) {
cout
<< "Automaton converting tool. Supports only dot format at the moment.\nUsage: aconvert [automaton.xml]\n";
return -1;
}
SaxInterface::parseFile(argv[1], tokens);
} else {
string input(istreambuf_iterator<char>(cin),
(istreambuf_iterator<char>()));
SaxInterface::parseMemory(input, tokens);
}
   
UnknownAutomaton unknownAutomaton = AutomatonParser::parse(tokens); if (argc > 1) {
Automaton* automaton = AutomatonFactory::buildAutomaton(unknownAutomaton); if (string(argv[1]) == "-v") {
DotConverter::convert(*automaton, cout); cout << USAGE;
cout << endl;
return EXIT_SUCCESS;
}
SaxInterface::parseFile(argv[1], tokens);
   
} catch (AlibException& e) { } else {
cout << e.what() << endl; string input(istreambuf_iterator<char>(cin),
return 0; (istreambuf_iterator<char>()));
SaxInterface::parseMemory(input, tokens);
} }
UnknownAutomaton unknownAutomaton = AutomatonParser::parse(tokens);
Automaton* automaton = AutomatonFactory::buildAutomaton(unknownAutomaton);
DotConverter::convert(*automaton, cout);
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* GasTexConverter.cpp * GasTexConverter.cpp
* *
* Created on: Jan 1, 2014 * Created on: Jan 1, 2014
* Author: martin * Author: Martin Zak
*/ */
   
#include "GasTexConverter.h" #include "GasTexConverter.h"
...@@ -18,8 +18,6 @@ void GasTexConverter::convert(const Automaton& a, ostream& out) { ...@@ -18,8 +18,6 @@ void GasTexConverter::convert(const Automaton& a, ostream& out) {
out << "\\begin{center}\n"; out << "\\begin{center}\n";
out << "\\begin{picture}(,)(,)\n"; out << "\\begin{picture}(,)(,)\n";
   
for (auto& state : a.getStates()) { for (auto& state : a.getStates()) {
bool initial = false; bool initial = false;
bool final = false; bool final = false;
...@@ -45,7 +43,7 @@ void GasTexConverter::convert(const Automaton& a, ostream& out) { ...@@ -45,7 +43,7 @@ void GasTexConverter::convert(const Automaton& a, ostream& out) {
} }
   
out << state.getName(); out << state.getName();
out << ")( , ){"; out << ")(,){";
out << state.getName(); out << state.getName();
out << "}\n"; out << "}\n";
} }
......
...@@ -2,26 +2,25 @@ ...@@ -2,26 +2,25 @@
* GasTexConverter.h * GasTexConverter.h
* *
* Created on: Jan 1, 2014 * Created on: Jan 1, 2014
* Author: martin * Author: Martin Zak
*/ */
   
#ifndef GASTEXCONVERTER_H_ #ifndef GASTEXCONVERTER_H_
#define GASTEXCONVERTER_H_ #define GASTEXCONVERTER_H_
   
#include<ostream> #include<ostream>
#include<map>
#include <automaton/FSM/FSM.h> #include<utility>
#include <automaton/PDA/PDA.h> #include"automaton/FSM/FSM.h"
#include <automaton/TM/TM.h> #include"automaton/PDA/PDA.h"
#include <map> #include"automaton/TM/TM.h"
#include <utility>
   
using namespace std; using namespace std;
using namespace automaton; using namespace automaton;
   
class GasTexConverter { class GasTexConverter {
private: private:
static void printTransitionMap(const map<pair<string, string>, string> transitionMap, ostream& out); static void printTransitionMap( const map<pair<string, string>, string> transitionMap, ostream& out);
static string checkEpsilon(const string& inputSymbol); static string checkEpsilon(const string& inputSymbol);
static string getStackSymbols(const list<Symbol>& stackSymbols); static string getStackSymbols(const list<Symbol>& stackSymbols);
static void transitions(const FSM& fsm, ostream& out); static void transitions(const FSM& fsm, ostream& out);
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
//============================================================================ //============================================================================
   
#include <iostream> #include <iostream>
#include "automaton/AutomatonParser.h" #include "automaton/AutomatonParser.h"
#include "automaton/UnknownAutomaton.h" #include "automaton/UnknownAutomaton.h"
#include "AutomatonFactory.h" #include "AutomatonFactory.h"
...@@ -13,6 +12,9 @@ ...@@ -13,6 +12,9 @@
   
#include "GasTexConverter.h" #include "GasTexConverter.h"
   
#define VERSION "0.0.1"
#define USAGE "aconvert.gastex [inputfile]"
using namespace std; using namespace std;
using namespace automaton; using namespace automaton;
using namespace sax; using namespace sax;
...@@ -20,28 +22,23 @@ using namespace alib; ...@@ -20,28 +22,23 @@ using namespace alib;
   
int main(int argc, char** argv) { int main(int argc, char** argv) {
list<Token> tokens; list<Token> tokens;
try {
if (argc > 1) {
if (string("-h").compare(argv[1]) == 0) {
cout
<< "Automaton converting tool. Supports only dot format at the moment.\nUsage: aconvert [automaton.xml]\n";
return -1;
}
SaxInterface::parseFile(argv[1], tokens);
} else {
string input(istreambuf_iterator<char>(cin),
(istreambuf_iterator<char>()));
SaxInterface::parseMemory(input, tokens);
}
   
UnknownAutomaton unknownAutomaton = AutomatonParser::parse(tokens); if (argc > 1) {
Automaton* automaton = AutomatonFactory::buildAutomaton(unknownAutomaton); if (string(argv[1]) == "-v") {
GasTexConverter::convert(*automaton, cout); cout << USAGE;
cout << endl;
return EXIT_SUCCESS;
}
SaxInterface::parseFile(argv[1], tokens);
   
} catch (AlibException& e) { } else {
cout << e.what() << endl; string input(istreambuf_iterator<char>(cin),
return 0; (istreambuf_iterator<char>()));
SaxInterface::parseMemory(input, tokens);
} }
UnknownAutomaton unknownAutomaton = AutomatonParser::parse(tokens);
Automaton* automaton = AutomatonFactory::buildAutomaton(unknownAutomaton);
GasTexConverter::convert(*automaton, cout);
} }
//============================================================================ //============================================================================
// Name : aconvert.cpp // Name : aconvert.cpp
// Author : Martin Zak // Author : Martin Zak
// Version :
// Copyright :
// Description :
//============================================================================ //============================================================================
   
#include <iostream> #include <iostream>
#include <string>
#include <cstdlib>
#include <unistd.h>
   
#include "automaton/AutomatonParser.h" #define PROGNAME "aconvert"
#include "automaton/UnknownAutomaton.h" #define VERSION "0.0.1"
#include "AutomatonFactory.h" #define USAGE "Usage: aconvert -t outputtype input";
#include "AlibException.h"
#include "sax/SaxInterface.h"
   
using namespace std; using namespace std;
using namespace automaton;
using namespace sax;
using namespace alib;
   
int main(int argc, char** argv) { int main(int argc, char** argv) {
list<Token> tokens; if(argc == 2 && string(argv[1])=="-v") {
try { cout << argv[0] << " version " << VERSION << "\n";
cout << USAGE;
if (argc > 1) { cout << endl;
if (string("-h").compare(argv[1]) == 0) { return EXIT_SUCCESS;
cout }
<< "Automaton converting tool. Supports only dot format at the moment.\nUsage: aconvert [automaton.xml]\n";
return -1;
}
SaxInterface::parseFile(argv[1], tokens);
} else {
string input(istreambuf_iterator<char>(cin),
(istreambuf_iterator<char>()));
SaxInterface::parseMemory(input, tokens);
}
   
UnknownAutomaton unknownAutomaton = AutomatonParser::parse(tokens); string outputType = "";
Automaton* automaton = AutomatonFactory::buildAutomaton(unknownAutomaton);
DotConverter::convert(*automaton, cout); int i=getopt(argc, argv, "t:");
while(i!=-1) {
switch(i){
case 't':
outputType = string(optarg);
break;
default:
optind--;
break;
}
i=getopt(argc, argv, "t:");
}
   
} catch (AlibException& e) { if(optind == argc || outputType == "") {
cout << e.what() << endl; cerr << USAGE;
return 0; cerr << endl;
return EXIT_FAILURE;
} else {
string programName = string(PROGNAME) + "." + string(outputType);
execv(programName.c_str(), argv + optind - 1);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment