00001
00002 #include <fstream>
00003
00004 #include "fsm.h"
00005 #include "parser.h"
00006
00007 int
00008 main(int argc, char* argv[]) {
00009 static const string USAGE("fsm2dot -- translate fsm to dot format filter");
00010 if (argc!=1) {
00011 cerr << USAGE << endl;
00012 return 1;
00013 }
00014
00015
00016 ref<Fsm> fsm = Parser(cin).parse();
00017
00018 if (!fsm) {
00019 cerr << "Syntax error in automaton description" << endl;
00020 return 2;
00021 }
00022
00023
00024
00025
00026
00027
00028
00029
00030 cout << "digraph G {\n"
00031 << "0 [shape=plaintext label=\"\"];\n"
00032 << "0 -> " << fsm->initial_state() << ";\n";
00033
00034
00035 for (Fsm::TRANSITIONS::const_iterator t=fsm->begin(); t!=fsm->end(); ++t)
00036 for (Fsm::STATES::const_iterator q=t->second.begin(); q!=t->second.end(); ++q)
00037 cout << (*t).first.first << " -> " << (*q)
00038 << " [label=\"" << (*t).first.second << "\"];\n";
00039
00040
00041 for (Fsm::STATES::const_iterator f=fsm->fbegin(); f!=fsm->fend(); ++f)
00042 cout << *f << " [shape=doublecircle];\n";
00043
00044 cout << "}\n";
00045
00046 return 0;
00047 }