Well, just before I went to bed I fixed the errors in NodeTree and GraphStructuredStack. To tackle RNGLRParser tommrow.
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <map>
|
||||||
#include "NodeTree.h"
|
#include "NodeTree.h"
|
||||||
|
#include "Symbol.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#ifndef GRAPH_STRUCTURED_STACK
|
#ifndef GRAPH_STRUCTURED_STACK
|
||||||
@@ -27,7 +29,7 @@ class GraphStructuredStack {
|
|||||||
std::string toString();
|
std::string toString();
|
||||||
private:
|
private:
|
||||||
std::vector<std::vector<NodeTree<int>*>*> gss;
|
std::vector<std::vector<NodeTree<int>*>*> gss;
|
||||||
std::map<std::pair<NodeTree<int>*, NodeTree<int>*>, NodeTree<Symbol*> edges;
|
std::map< std::pair< NodeTree<int>*, NodeTree<int>* >, NodeTree<Symbol*>* > edges;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ void NodeTree<T>::addChild(NodeTree<T>* child) {
|
|||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void NodeTree<T>::addChildren(std::vector<NodeTree<T>*>* children) {
|
void NodeTree<T>::addChildren(std::vector<NodeTree<T>*>* children) {
|
||||||
for (std::vector<NodeTree<T>*>::size_type i = 0; i < children->size(); i++)
|
for (typename std::vector<NodeTree<T>*>::size_type i = 0; i < children->size(); i++)
|
||||||
addChild((*children)[i]);
|
addChild((*children)[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ void NodeTree<T>::removeChild(NodeTree<T>* child) {
|
|||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void NodeTree<T>::clearChildren() {
|
void NodeTree<T>::clearChildren() {
|
||||||
for (std::vector<T>::size_type i = 0; i < children.size(); i++)
|
for (typename std::vector<T>::size_type i = 0; i < children.size(); i++)
|
||||||
children[i] = NULL;
|
children[i] = NULL;
|
||||||
children.clear();
|
children.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "Parser.h"
|
#include "Parser.h"
|
||||||
|
#include "Symbol.h"
|
||||||
#include "GraphStructuredStack.h"
|
#include "GraphStructuredStack.h"
|
||||||
|
|
||||||
class RNGLRParser: public Parser {
|
class RNGLRParser: public Parser {
|
||||||
@@ -45,7 +47,7 @@ class RNGLRParser: public Parser {
|
|||||||
int nullablePartsIndex;
|
int nullablePartsIndex;
|
||||||
NodeTree<Symbol*>* label;
|
NodeTree<Symbol*>* label;
|
||||||
} ;
|
} ;
|
||||||
std::queue<reduction> toReduce;
|
std::queue<Reduction> toReduce;
|
||||||
//Node coming from, state going to
|
//Node coming from, state going to
|
||||||
std::queue< std::pair<NodeTree<int>*, int> > toShift;
|
std::queue< std::pair<NodeTree<int>*, int> > toShift;
|
||||||
std::vector<std::pair<NodeTree<Symbol*>*, int> > SPPFStepNodes;
|
std::vector<std::pair<NodeTree<Symbol*>*, int> > SPPFStepNodes;
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ NodeTree<int>* GraphStructuredStack::inFrontier(int frontier, int state) {
|
|||||||
|
|
||||||
int GraphStructuredStack::getContainingFrontier(NodeTree<int>* node) {
|
int GraphStructuredStack::getContainingFrontier(NodeTree<int>* node) {
|
||||||
for (std::vector<std::vector<NodeTree<int>*>*>::size_type i = 0; i < gss.size(); i++) {
|
for (std::vector<std::vector<NodeTree<int>*>*>::size_type i = 0; i < gss.size(); i++) {
|
||||||
if (frontierIsEmpty(frontier))
|
if (frontierIsEmpty(i))
|
||||||
continue;
|
continue;
|
||||||
for (std::vector<NodeTree<int>*>::size_type j = 0; j < gss[i]->size(); j++) {
|
for (std::vector<NodeTree<int>*>::size_type j = 0; j < gss[i]->size(); j++) {
|
||||||
if (*((*(gss[i]))[j]) == *node)
|
if ((*(gss[i]))[j] == node)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,9 +96,9 @@ void GraphStructuredStack::recursivePathFind(NodeTree<int>* start, int length, s
|
|||||||
paths->push_back(currentPath);
|
paths->push_back(currentPath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::vector<NodeTree<int>*>* children = start->getChildren();
|
std::vector<NodeTree<int>*> children = start->getChildren();
|
||||||
for (std::vector<NodeTree<int>*>::size_type i = 0; i < children->size(); i++) {
|
for (std::vector<NodeTree<int>*>::size_type i = 0; i < children.size(); i++) {
|
||||||
recursivePathFind((*children)[i], length-1, currentPath, paths);
|
recursivePathFind(children[i], length-1, currentPath, paths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,10 +108,10 @@ bool GraphStructuredStack::hasEdge(NodeTree<int>* start, NodeTree<int>* end) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NodeTree<Symbol*>* GraphStructuredStack::getEdge(NodeTree<int>* start, NodeTree<int>* end) {
|
NodeTree<Symbol*>* GraphStructuredStack::getEdge(NodeTree<int>* start, NodeTree<int>* end) {
|
||||||
return edges.get(std::make_pair(start, end), NULL);
|
return edges[std::make_pair(start, end)];
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphStructuredStack::addEdge(NodeTree<int>* start, NodeTree<int>* end, NodeTree<Symbol*> edge) {
|
void GraphStructuredStack::addEdge(NodeTree<int>* start, NodeTree<int>* end, NodeTree<Symbol*>* edge) {
|
||||||
start->addChild(end);
|
start->addChild(end);
|
||||||
end->addParent(start);
|
end->addParent(start);
|
||||||
edges[std::make_pair(start, end)] = edge;
|
edges[std::make_pair(start, end)] = edge;
|
||||||
|
|||||||
Reference in New Issue
Block a user