Added structure for Regular Expressions, saving work as a backup because of software upgrade.

This commit is contained in:
Nathan Braswell
2013-07-01 22:45:33 -04:00
parent c2520ec2c4
commit 94a7739bd9
9 changed files with 179 additions and 10 deletions

View File

@@ -3,6 +3,7 @@
#include "util.h"
#include "StringReader.h"
#include "RegEx.h"
#include "Symbol.h"
#include <string>
@@ -12,9 +13,12 @@ class Lexer {
Lexer();
Lexer(std::string inputString);
~Lexer();
void addRegexString(std::string regExString);
void setInput(std::string inputString);
Symbol* next();
private:
StringReader reader;
std::vector<RegEx*> regExs;
std::string input;
int currentPosition;
};
#endif

23
include/RegEx.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef REGEX_H
#define REGEX_H
#include "util.h"
#include "RegExState.h"
#include "Symbol.h"
#include <string>
class RegEx {
public:
RegEx();
RegEx(std::string inPattern);
~RegEx();
int longMatch(std::string stringToMatch);
std::string getPattern();
private:
std::string pattern;
RegExState* begin;
std::vector<RegExState*> currentStates;
};
#endif

27
include/RegExState.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef REGEXSTATE_H
#define REGEXSTATE_H
#include "util.h"
#include "Symbol.h"
#include <string>
#include <vector>
class RegExState {
public:
RegExState(RegExState* inInnerState);
RegExState(char inCharacter);
~RegExState();
void addNext(RegExState* nextState);
bool characterIs(char inCharacter);
std::vector<RegExState*>* advance(char advanceCharacter);
bool isGoal();
private:
std::vector<RegExState*> nextStates;
RegExState* inner;
char character;
};
#endif

View File

@@ -16,6 +16,7 @@ class NodeTree;
class Symbol {
public:
Symbol(std::string name, bool isTerminal);
Symbol(std::string name, bool isTerminal, std::string value);
Symbol(std::string name, bool isTerminal, NodeTree* tree);
~Symbol();
bool const operator==(const Symbol &other);
@@ -30,8 +31,6 @@ class Symbol {
std::string value;
bool terminal;
NodeTree* subTree;
};
#endif