File: FSA.h

package info (click to toggle)
magnus 20060324-5.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 19,436 kB
  • ctags: 20,462
  • sloc: cpp: 130,217; ansic: 37,090; tcl: 10,970; perl: 1,109; makefile: 966; sh: 403; yacc: 372; csh: 57; awk: 33; asm: 10
file content (73 lines) | stat: -rw-r--r-- 2,130 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (C) 1994 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.

// Contents: The finite state automaton class
//
// Principal Author: Sarah Rees
//
// Status: in progress
//
// Revision History:
//
// * 08/96 Dmitry B. implemented IPC tools.
//

#ifndef _FSA_H_
#define _FSA_H_

#include <Integer.h>
#include "global.h"
#include "ObjectOf.h"
#include "FSARep.h"

class FSA : public ObjectOf<FSARep> {
public:
  Bool accepts(Word w) const { return look()->accepts(w); }
  Bool rejectsInState(Word w, int& state) const {
	 return look()->rejectsInState(w, state);
  }
  Bool nextAcceptedWord(Word& w) const {
	 return look()->nextAcceptedWord(w);
  }
//Bool nextAcceptedWord(Word w, int*& history) const = 0; // bad arg
  void minimize() { change()->minimize(); }
  Integer sizeLanguage() const { return look()->sizeLanguage();}
  Bool finiteLanguage() const { return look()->finiteLanguage();}
  
  void readFrom(istream &str = cin) { change()->readFrom(str); }
  void printOn(ostream &str = cout) const { look()->printOn(str); }
  void setName(const Chars & name) { change()->setName(name);}
  int getNumStates() const { return look()->getNumStates();}
  int operator == ( const FSA & F ) const {
         return ((look() == F.look()) || (*look() == *F.look()));
  }

  int operator != ( const FSA & F ) const {
         return ((look() != F.look()) && (!(*look() == *F.look())));
  }
  

  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // IPC tools:                                                          //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  friend ostream& operator < ( ostream& ostr, const FSA& fsa )
  {
    fsa.look()->write(ostr);
    return ostr;
  }
  
  friend istream& operator > ( istream& istr, FSA& fsa )
  {
    fsa.change()->read(istr);
    return istr;
  }


protected:
  typedef ObjectOf<FSARep> R;
  FSA( FSARep *p ) : R(p) {}
};
#endif