Here's the class definition inside DetFinAut.h:
Expand|Select|Wrap|Line Numbers
- #ifndef DETFINAUT_H
- #define DETFINAUT_H
- #include <iostream>
- #include <string>
- class DetFinAut
- {
- public:
- DetFinAut();
- DetFinAut(char,int,int,int,int,std::string);
- static void restart();
- static char run(std::string);
- private:
- char languageABC[36];
- int numStates;
- static int startState;
- static std::string outputs[6];
- int transTable[6][36];
- public:
- static void step(char);
- };
- #endif
Expand|Select|Wrap|Line Numbers
- #include "detfinaut.h"
- #include <iostream>
- #include <string>
- using namespace std;
- DetFinAut::DetFinAut(char inputABCIn[36], int numStatesIn, int startState, int acceptStatesIn, int tableIn[6][36], string outputsDef[])
- {
- languageABC = inputABCIn;
- numStates = startState;
- startState = numStatesIn;
- transTable = tableIn;
- outputs = *outputsDef;
- DetFinAut::restart();
- }
- void DetFinAut::restart()
- {
- actState = startState;
- stopped = false;
- }
- void DetFinAut::step(string inputs)
- {
- if(!DetFinAut::isStopped())
- {
- if (nextState(actState,inputs) == -1) stopped = true;
- else actState = destination;
- }
- }
- char DetFinAut::run(string inputs)
- {
- for(int i=0; i<inputs.length(); i++)
- {
- step(inputs[i]);
- if (isStopped()) break;
- }
- if (isAccepting()) return getOutput(getState());
- else return NULL;
- }
Barnz