Fixes for state generation to reduce memory usage - adding in optional semicolons balooned our memory usage to somewhere under 8 gigs, with some simple refactoring we're back down to a bit over 4. Needs to be smaller, but it's an improvement

This commit is contained in:
Nathan Braswell
2015-03-23 14:35:28 -04:00
parent f8e82b5302
commit 2c4dbc60d1
11 changed files with 89 additions and 100 deletions

View File

@@ -12,9 +12,15 @@
#include <iostream>
class ParseRule {
private:
int pointerIndex;
Symbol leftHandle;
std::vector<Symbol> lookahead;
std::vector<Symbol> rightSide;
public:
ParseRule();
ParseRule(Symbol leftHandle, int pointerIndex, std::vector<Symbol> &rightSide, std::vector<Symbol>* lookahead);
ParseRule(Symbol leftHandle, int pointerIndex, std::vector<Symbol> &rightSide, std::vector<Symbol> lookahead);
~ParseRule();
const bool equalsExceptLookahead(const ParseRule &other) const;
bool const operator==(const ParseRule &other) const;
@@ -36,19 +42,12 @@ class ParseRule {
bool advancePointer();
bool isAtEnd();
void setLookahead(std::vector<Symbol>* lookahead);
void addLookahead(std::vector<Symbol>* lookahead);
std::vector<Symbol>* getLookahead();
void setLookahead(std::vector<Symbol> lookahead);
void addLookahead(std::vector<Symbol> lookahead);
std::vector<Symbol> getLookahead();
std::string toString(bool printLookahead = true);
std::string toDOT();
private:
int pointerIndex;
Symbol leftHandle;
std::vector<Symbol>* lookahead;
std::vector<Symbol> rightSide;
};
#endif

View File

@@ -44,7 +44,7 @@ class Parser {
std::map<Symbol, std::vector<Symbol>> tokenFirstSet;
std::map<Symbol, bool> tokenNullable;
std::vector<Symbol>* incrementiveFollowSet(ParseRule* rule);
std::vector<Symbol> incrementiveFollowSet(ParseRule* rule);
virtual void closure(State* state);
virtual void addStates(std::vector< State* >* stateSets, State* state, std::queue<State*>* toDo);
int stateNum(State* state);

View File

@@ -24,7 +24,7 @@ class State {
bool const operator!=(const State &other);
std::vector<ParseRule*>* getBasis();
std::vector<ParseRule*>* getRemaining();
std::vector<ParseRule*>* getTotal();
std::vector<ParseRule*> getTotal();
bool containsRule(ParseRule* rule);
void addRuleCombineLookahead(ParseRule* rule);
std::string toString();
@@ -40,8 +40,7 @@ class State {
std::vector<ParseRule*> remaining;
private:
std::vector<State*> parents;
std::vector<ParseRule*> total;
int number;
};
#endif
#endif