#include <fstream>
#include "fsm.h"
#include "parser.h"
Include dependency graph for fsm2dot.C:
Go to the source code of this file.
Functions | |
int | main (int argc, char *argv[]) |
Main function for the fsm program. More... |
|
Main function for the fsm program.
Definition at line 8 of file fsm2dot.C. 00008 { 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 // Input automaton. 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 // Generate dot file. 00024 00025 // Trick: use special ``0'' node with not label and no shape and an 00026 // arrow from 0 to the initial state. This will show up as an arrow 00027 // coming from nowhere to the initial state, the convention for the 00028 // graphical representation of an automaton. 00029 00030 cout << "digraph G {\n" 00031 << "0 [shape=plaintext label=\"\"];\n" 00032 << "0 -> " << fsm->initial_state() << ";\n"; 00033 00034 // Draw an edge for each transition. 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 // Use doublecircle shape for final states. 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 } |