Changed followset to work on states, fixed many bugs. Kraken now should have a fairly legitimate LALR(1) parser. (null productions have not yet been added.)

This commit is contained in:
Nathan Braswell
2013-06-23 05:06:38 -04:00
parent 17dd186373
commit a307e1f143
5 changed files with 88 additions and 34 deletions

View File

@@ -26,9 +26,8 @@ class Parser {
std::vector<Symbol*>* firstSet(Symbol* token);
void printFirstSets();
//std::vector<Symbol*>* followSet(int stateNum, Symbol* token);
std::vector<Symbol*>* gramFollowSet(Symbol* token);
std::vector<Symbol*>* gramFollowSetAvoid(Symbol* token, std::vector<Symbol*>* avoidList);
void printFollowSets();
std::vector<Symbol*>* gramFollowSet(State* state, Symbol* token);
std::vector<Symbol*>* gramFollowSetAvoid(State* state, Symbol* token, std::vector<Symbol*>* avoidList);
void createStateSet();
void closure(State* state);
void addStates(std::vector< State* >* stateSets, State* state);

View File

@@ -16,6 +16,7 @@
class State {
public:
State(int number, ParseRule* basis);
State(int number, ParseRule* basis, State* parent);
~State();
bool const operator==(const State &other);
bool const basisEquals(const State &other);
@@ -26,10 +27,15 @@ class State {
bool containsRule(ParseRule* rule);
std::string toString();
void addParents(std::vector<State*>* parents);
std::vector<State*>* getParents();
std::vector<State*>* getDeepParents(int depth);
std::vector<ParseRule*> basis;
std::vector<ParseRule*> remaining;
private:
std::vector<State*> parents;
std::vector<ParseRule*> total;
int number;
};