#include <astl.h>
#include <dfa_map.h>
#include "cursor.h"
#include "language.h"
#include "filter.h"
#include "set_operation.h"
#include <astl_tree.h>
#include <iterator>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include "ccopy.h"
#include <minimize.h>
#include "sigma_star.h"
#include <debug.h>
#include <string_cursor.h>

typedef DFA_map<plain, minimization_tag> DFA;
typedef forward_cursor<DFA> ForwardCursor;

// compile with:
// g++ -Wall -O3 -I../include -I../cursors -fno-exceptions sample.cpp

// Test set operations:
// Usage: a.out dictionary
// dico contains one word per line (/usr/dict/words)
// display all words in the dictionary ending by the entered word (Sigma*
// concatenated with the word)

int main(int argc, char **argv)
{
  DFA dfa1, dfa2;  
  if (argc > 1) {
    ifstream f1;
    f1.open(argv[1], ios::in);
    if (!f1) exit(2);
    tree_build(dfa1, istream_iterator<string>(f1), istream_iterator<string>());
    f1.close();
  }
  cout << "dfa1::Q = " << dfa1.state_count() << " ::T = " << dfa1.trans_count()
       << endl;
  cout << "minimizing...";
  cout.flush();
  acyclic_minimization(dfa1);
  cout << endl << "dfa1::Q = " << dfa1.state_count() << " ::T = " << dfa1.trans_count()
       << endl;

  while(1) {
    string w;
    cout << "Ok" << endl;
    cin >> w;
    ostream_iterator<char> output(cerr);

    language(output, dfirstc(intersectionc(debugc(dfa1),  
					concatenationc(
						       sigma_starc(), 
						       stringc(w.c_str())))));
  }
  
  cout << "exit." << endl;
  return 0;
}
  
  









