#!/usr/bin/env python """ dfa_min.py Usage: dfa_min.py Read a Deteministic Finite Automaton specification and minimize it. Options: -h --help Print this help. -d --dot Print a description of the automaton in the Graphviz language suitable for processing with dot to get a graphical representation of the automaton. -p --print Print back the automaton in tabular form. -g --graphviz Parse the automaton in Graphviz format (default is tabular form). This is not the most robust parser - caveat emptor! Copyright 2015 Stephan Schulz, schulz@eprover.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program ; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA The original copyright holder can be contacted as Stephan Schulz DHBW Stuttgart Informatik Postfach 10 05 63 D-70004 Stuttgart Germany or via email (address above). """ import sys import getopt from pylib_dfa import DFA dot = False prt = False gv = False if __name__ == '__main__': opts, args = getopt.gnu_getopt(sys.argv[1:], "hdpg", ["help", "dot", "print", "graphviz"]) for option, optarg in opts: if option in ["-h", "--help"]: print (__doc__) sys.exit() elif option in ["-d", "--dot"]: dot = True elif option in ["-p", "--print"]: prt = True elif option in ["-g", "--graphviz"]: gv = True else: sys.exit("Unknown option "+ option) if len(args)<1: file = sys.stdin else: file = open(args[0], "r") str = file.read() if file!=sys.stdin: file.close() dfa = DFA() if gv: dfa.parse_gv(str) else: dfa.parse(str) # print (dfa) table = dfa.minimize() print (table) if prt: print (dfa) print if dot: print (dfa.dotify()) print