File: DFSAParser.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 (119 lines) | stat: -rw-r--r-- 3,217 bytes parent folder | download | duplicates (2)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (C) 1994 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.

// Contents: Definition of DFSA parser class.
//
// Principal Author: Sarah Rees
//
// Status: in progress
//
// Revision History:
//

#ifndef _DFSA_PARSER_H_
#define _DFSA_PARSER_H_

#include <iostream>
#include <iomanip>
//#include <stdiostream.h>
#include "global.h"
#include "DFSARep.h"


enum { SIMPLE=0, WORDS=1, LABELED=2}; // types for states

class DFSAParser {
public:

  DFSAParser(istream  &istr,int stype,Bool useInv) : 
         name(""),
         str(istr),
	 parses(1),
	 table(0),
	 alphabet(0),
         baseAlphabet(0),
         stateAlphabet(0),
         symbolOrder(1), 
         symbolForColumn(1),
	 stateWordLabels(0),
	 stateCharsLabels(0),
// use the default constructor for stateLabelsIndex. Initialising on 0 puts
// the integer 0 as first entry of the list
	 numStates(0),
	 numSymbols(0),
         numTransits(0),
	 numStrings(0),
         minimized(NO),
         stateType(stype),
         useInverses(useInv)
  { symbolOrder[0]=0; symbolForColumn[0]=0;}

  ~DFSAParser() {
	 delete [] table;
  }

  void parseError(char * errormessage);
  void setDFSA(DFSARep * M);
  void setDFSA(GroupDFSARep * M);
  ListOf<int> getStateLabelsIndex() const {return stateLabelsIndex;};
  VectorOf<Chars> getStateCharsLabels() const {return stateCharsLabels;};
  VectorOf<Word> getStateWordLabels() const {return stateWordLabels;};
  void setAlphabet(DFSARep * M);
  void setAlphabet(GroupDFSARep * M);
  void setFlags(DFSARep * M);
  void setData(DFSARep * M);
  Bool parseDFSA(DFSARep * M);
  void parseAlphabetRec();
  void matchAlphabet(DFSARep * M);
  void matchAlphabet(GroupDFSARep * M);
  void parseStatesRec();
  void parseFlags();
  void parseAccepting();
  void parseTableRec();
  void setStateAlphabet(DFSARep * M);
  void parseStateLabelsRec();
  void parseStateWordLabels();

  
private:
  typedef DFSARep::State State;
  typedef DFSARep::GeneratorIndex GeneratorIndex;

// The basis of a DFSAParser is its table, which is simply an int **.
// The states are consecutive integers 1,2,3,.. numstates, with 0 as the
// fail state.  The states index the columns and the alphabet symbols the
// rows of the array.  The 0-th row is used to store the categories of
// the states.

  int ** table; 
  Chars name;
  VectorOf<Chars> alphabet;
  VectorOf<Chars> baseAlphabet;
  VectorOf<Chars> stateAlphabet;
  VectorOf<int> symbolOrder;
  VectorOf<int> symbolForColumn;
  Chars paddingSymbol;
  int stateType; // equal to SIMPLE, WORDS or LABELED
  VectorOf<Word> stateWordLabels;
  VectorOf<Chars> stateCharsLabels;
  ListOf<int> stateLabelsIndex;
  int numStates;  // Not including the fail state 0.
  int numSymbols; // The alphabet size.
  int numTransits; // number of transitions (essentially the square of the 
    // alphabet size for a 2 string automaton )
  int numStrings;
  Bool minimized;
  Bool useInverses;
  istream& str;
  Bool getInt(int &);
  Bool readToToken();
  Bool getToken(int &);
  Bool getToken(Chars &);
  Chars getToken();
  Bool checkToken(const char * token);
  Bool checkToken(const char ch);
  void parseTable(Bool compressed);
  Bool parses;
};

#endif