Modifed set creation to use a State object. Set creation works

This commit is contained in:
Nathan Braswell
2013-05-26 22:12:47 -04:00
parent 858daa30ee
commit 315dc55409
7 changed files with 185 additions and 56 deletions

View File

@@ -18,6 +18,7 @@ class ParseRule {
~ParseRule();
bool const operator==(const ParseRule &other);
bool const operator!=(const ParseRule &other);
ParseRule* clone();
@@ -26,6 +27,9 @@ class ParseRule {
Symbol* getLeftSide();
std::vector<Symbol*> getRightSide();
Symbol* getAtNextIndex();
Symbol* getAtIndex();
int getRightSize();
int getIndex();
bool advancePointer();

View File

@@ -8,13 +8,13 @@
#include "ParseRule.h"
#include "ParseAction.h"
#include "Symbol.h"
#include "State.h"
#include "StringReader.h"
#include <map>
#include <vector>
#include <stack>
#include <string>
#include <sstream>
#include <iostream>
class Parser {
@@ -22,12 +22,10 @@ class Parser {
Parser();
~Parser();
std::string intToString(int theInt);
void loadGrammer(std::string grammerInputString);
void createStateSet();
void closure(std::vector<ParseRule*>* state);
void addState(std::vector< std::vector<ParseRule*>* >* stateSets, std::vector<ParseRule*>* state, Symbol*);
void closure(State* state);
void addState(std::vector< State* >* stateSets, State* state, Symbol*);
std::string stateSetToString();
int gotoTable(int state, Symbol* token);
ParseAction* actionTable(int state, Symbol* token);
@@ -40,7 +38,7 @@ class Parser {
std::map<std::string, Symbol*> symbols;
std::vector<ParseRule*> loadedGrammer;
std::vector< std::vector<ParseRule*>* > stateSets;
std::vector< State* > stateSets;
std::stack<int> stateStack;
std::stack<Symbol*> symbolStack;

36
include/State.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef STATE_H
#define STATE_H
#ifndef NULL
#define NULL 0
#endif
#include "ParseRule.h"
#include <vector>
#include <string>
#include <string>
#include <sstream>
class State {
public:
State(int number, ParseRule* basis);
~State();
std::string intToString(int theInt);
bool const operator==(const State &other);
bool const operator!=(const State &other);
std::vector<ParseRule*>* getBasis();
std::vector<ParseRule*>* getRemaining();
std::vector<ParseRule*>* getTotal();
bool containsRule(ParseRule* rule);
std::string toString();
std::vector<ParseRule*> basis;
std::vector<ParseRule*> remaining;
private:
std::vector<ParseRule*> total;
int number;
};
#endif