-
Notifications
You must be signed in to change notification settings - Fork 0
/
NFA.hpp
65 lines (51 loc) · 1.7 KB
/
NFA.hpp
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
/*
* File: NFA.hpp
*
* Modified by: Sean Sponsler and Evan Waletrs
* Date: May 20th, 2023
* DESC: This file contians the description of a class named NFA, as well as
* other functions for utility/main usage.
*/
#include <iostream>
#include <vector>
#include <utility> // pair
#include <queue>
#include <stack>
#include <string>
#include <assert.h>
#include <algorithm>
class NFA {
public:
// Constructors & Destructor
NFA() {};
NFA(char operand);
NFA(NFA M1, char op, NFA M2 = NFA());
~NFA() {};
void removeEpsilon();
bool bfs(std::string input);
bool isFinal(int state);
void addFinalState(int state);
// inline set functions
void setFinalStates(std::vector<int> final) { _finalStates = final; }
void setDelta(std::vector<std::vector<std::pair<int, char>>> delta) { _delta = delta; }
// inline get functions
int getSize() { return _size; }
int getStart() { return _startState; }
std::vector<int> getFinalStates() { return _finalStates; }
std::vector<std::vector<std::pair<int, char>>> getDelta() { return _delta; }
// print function for testing
void print();
private:
std::vector<int> _finalStates;
int _startState = 0;
int _size = 0;
// 2d vector of pairs (result state, transition operand)
std::vector<std::vector<std::pair<int, char>>> _delta;
};
// Other functions for utility/main usage.
void accepts(std::string RE, std::string w);
bool isOp(char c);
int prio(char c);
std::string infixToPrefix(std::string RE);
NFA convert(std::string w);
std::pair<NFA, int> convertHelper(int i, std::string w);