Example #1
0
// showDFA performs common actions for individual and merged DFAs
// it returns the ultimate (original or minimized) dfa
func showDFA(dfa *rx.DFA, treelabel string, showtime bool) *rx.DFA {
	if *opt['p'] {
		dfa.ShowTree(os.Stdout, dfa.Tree, treelabel)
	}
	if *opt['n'] {
		dfa.ShowNFA(os.Stdout, "NFA")
	}
	if *opt['d'] {
		dfa.ShowStates(os.Stdout, "Unoptimized DFA")
	}
	if !*opt['u'] {
		if showtime {
			rxsys.Interval() // reset for timing
		}
		dfa = dfa.Minimize()
		if showtime {
			timestamp(fmt.Sprintf(
				"minimize to %d states", len(dfa.Dstates)))
		}
		if *opt['d'] {
			dfa.ShowStates(os.Stdout, "Minimized DFA")
		}
	}
	if *opt['h'] {
		synthx(dfa)
	}
	return dfa
}
Example #2
0
//  print NFA and DFA, with buttons linking to display page
func showaut(w http.ResponseWriter, dfa *rx.DFA, exprlist []string) {

	fmt.Fprintln(w, `<div><div class=lfloat>`)

	nfaBuffer := &bytes.Buffer{}
	dfa.ShowNFA(nfaBuffer, "")
	fmt.Fprintf(w, "<h2>NFA</h2><PRE class=smaller>\n%s</PRE>\n",
		hx(string(nfaBuffer.Bytes())))
	formlink(w, "/drawNFA", exprlist, "Draw the graph")

	fmt.Fprintln(w, `</div><div class=lstripe>`)
	dfaBuffer := &bytes.Buffer{}
	dfa.ShowStates(dfaBuffer, "")
	fmt.Fprintf(w,
		"<h2 class=noadvance>DFA</h2><PRE class=smaller>\n%s</PRE>\n",
		hx(string(dfaBuffer.Bytes())))
	formlink(w, "/drawDFA", exprlist, "Draw the graph")

	fmt.Fprintln(w, `</div></div><div class=reset></div>`)
}