Changed Table to store vectors of actions, changed Parser appropriately.

This commit is contained in:
Nathan Braswell
2013-07-28 23:48:10 -04:00
parent 6d7b38a03b
commit 733fe1c08d
8 changed files with 142 additions and 72 deletions

View File

@@ -1,6 +1,6 @@
#include <iostream>
#include <vector>
#include "GSSNode.h"
#include "NodeTree<int>.h"
#ifndef GRAPH_STRUCTURED_STACK
#define GRAPH_STRUCTURED_STACK
@@ -9,15 +9,15 @@ class GraphStructuredStack {
public:
GraphStructuredStack();
~GraphStructuredStack();
GSSNode* newNode(int stateNum);
void addToFrontier(int frontier, GSSNode* node);
bool inFrontier(int frontier, int state);
NodeTree<int>* newNode(int stateNum);
void addToFrontier(int frontier, NodeTree<int>* node);
NodeTree<int>* inFrontier(int frontier, int state);
bool frontierIsEmpty(int frontier);
bool frontierHasAccState(int frontier);
std::vector<GSSNode*>* getReachable(GSSNode* start, int lenght);
bool hasEdge(GSSNode* start, GSSNode* end);
void addEdge(GSSNode* start, GSSNode* end);
std::vector<NodeTree<int>*>* getReachable(NodeTree<int>* start, int lenght);
bool hasEdge(NodeTree<int>* start, NodeTree<int>* end);
void addEdge(NodeTree<int>* start, NodeTree<int>* end);
private:
std::vector<std::vector<GSSNode*>*> gss;
std::vector<std::vector<NodeTree<int>*>*> gss;
//
};

View File

@@ -22,15 +22,18 @@ class NodeTree {
NodeTree(std::string name, T inData);
~NodeTree();
void setParent(NodeTree* parent);
NodeTree* getParent();
void setParent(NodeTree<T>* parent);
void addParent(NodeTree<T>* parent);
NodeTree<T>* getParent();
std::vector<NodeTree<T>*> getParents();
void addChild(NodeTree* child);
int findChild(NodeTree* child);
void removeChild(NodeTree* child);
void addChild(NodeTree<T>* child);
int findChild(NodeTree<T>* child);
void removeChild(NodeTree<T>* child);
void removeChild(int index);
std::vector<NodeTree<T>*> getChildren();
NodeTree* get(int index);
NodeTree<T>* get(int index);
std::string getName();
void setName(std::string);
@@ -46,8 +49,8 @@ class NodeTree {
std::string getDOTName();
std::string name;
T data;
NodeTree* parent;
std::vector<NodeTree*> children;
std::vector<NodeTree<T>*> parents;
std::vector<NodeTree<T>*> children;
static int idCounter;
int id;
@@ -59,7 +62,6 @@ int NodeTree<T>::idCounter;
template<class T>
NodeTree<T>::NodeTree() {
parent = NULL;
name = "UnnamedNode";
data = NULL;
@@ -68,7 +70,6 @@ NodeTree<T>::NodeTree() {
template<class T>
NodeTree<T>::NodeTree(std::string name, T inData) {
parent = NULL;
data = NULL;
this->name = name;
this->data = inData;
@@ -78,21 +79,33 @@ NodeTree<T>::NodeTree(std::string name, T inData) {
template<class T>
NodeTree<T>::~NodeTree() {
children.clear();
parents.clear(); //? Will this segfault?
}
template<class T>
void NodeTree<T>::setParent(NodeTree<T>* parent) {
if (this->parent != NULL) {
this->parent->removeChild(this);
}
this->parent = parent;
parents.clear();
parents.push_back(parent);
}
template<class T>
void NodeTree<T>::addParent(NodeTree<T>* parent) {
parents.push_back(parent);
}
template<class T>
NodeTree<T>* NodeTree<T>::getParent() {
return parent;
if (parents.size() > 0)
return parents[0];
return NULL;
}
template<class T>
std::vector<NodeTree<T>*> NodeTree<T>::getParents() {
return parents;
}
template<class T>
void NodeTree<T>::addChild(NodeTree<T>* child) {
if (findChild(child) == -1)
@@ -118,11 +131,16 @@ void NodeTree<T>::removeChild(int index) {
template<class T>
void NodeTree<T>::removeChild(NodeTree<T>* child) {
int index = findChild(child);
if (index != 0) {
if (index != -1) {
removeChild(index);
}
}
template<class T>
std::vector<NodeTree<T>*> NodeTree<T>::getChildren() {
return &children;
}
template<class T>
int NodeTree<T>::size() {
int count = 0;

View File

@@ -11,7 +11,7 @@ class RNGLRParser {
std::vector<Symbol*> input;
GraphStructuredStack gss;
//start node, lefthand side of the reduction, reduction length
std::queue<std::pair< std::pair<GSSNode*, Symbol*>, int > toReduce;
std::queue<std::pair< std::pair<NodeTree<int>*, Symbol*>, int > toReduce;
//Node coming from, state going to
std::queue< std::pair<GSSNode*, int> > toShift;
std::queue< std::pair<NodeTree<int>*, int> > toShift;
};

View File

@@ -13,10 +13,10 @@ class Table {
~Table();
void setSymbols(Symbol* EOFSymbol, Symbol* nullSymbol);
void add(int stateNum, Symbol* tranSymbol, ParseAction* action);
ParseAction* get(int state, Symbol* token);
std::vector<ParseAction*>* get(int state, Symbol* token);
std::string toString();
private:
std::vector< std::vector<ParseAction*>* > table;
std::vector< std::vector< std::vector<ParseAction*>* >* > table;
std::vector<Symbol*> symbolIndexVec;
//The EOFSymbol, a pointer because of use in table, etc
Symbol* EOFSymbol;