Fixed all syntax errors, but NULL crops up where it shouldn't. Checks for it as stop-gap, creates very truncated trees. Does run, and still correctly accepts. Calling it a night.
This commit is contained in:
@@ -22,6 +22,9 @@ class NodeTree {
|
||||
NodeTree(std::string name, T inData);
|
||||
~NodeTree();
|
||||
|
||||
bool const operator==(NodeTree &other);
|
||||
bool const operator<(const NodeTree &other) const;
|
||||
|
||||
void setParent(NodeTree<T>* parent);
|
||||
void addParent(NodeTree<T>* parent);
|
||||
NodeTree<T>* getParent();
|
||||
@@ -36,11 +39,10 @@ class NodeTree {
|
||||
std::vector<NodeTree<T>*> getChildren();
|
||||
|
||||
NodeTree<T>* get(int index);
|
||||
|
||||
std::string getName();
|
||||
void setName(std::string);
|
||||
|
||||
T getData();
|
||||
T getData() const;
|
||||
void setData(T data);
|
||||
|
||||
int size();
|
||||
@@ -83,6 +85,23 @@ NodeTree<T>::~NodeTree() {
|
||||
parents.clear(); //? Will this segfault?
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const bool NodeTree<T>::operator==(NodeTree &other) {
|
||||
if (!(data == other.data))
|
||||
return false;
|
||||
if (children.size() != other.getChildren().size())
|
||||
return false;
|
||||
for (typename std::vector<NodeTree<T>*>::size_type i = 0; i < children.size(); i++)
|
||||
if (! (*(children[i]) == *(other.getChildren()[i])))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const bool NodeTree<T>::operator<(const NodeTree &other) const {
|
||||
return data < other.getData();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void NodeTree<T>::setParent(NodeTree<T>* parent) {
|
||||
parents.clear();
|
||||
@@ -180,7 +199,7 @@ void NodeTree<T>::setName(std::string name) {
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T NodeTree<T>::getData() {
|
||||
T NodeTree<T>::getData() const {
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -198,7 +217,10 @@ template<class T>
|
||||
std::string NodeTree<T>::DOTGraphStringHelper() {
|
||||
std::string ourDOTRelation = "";
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
ourDOTRelation += getDOTName() + " -> " + children[i]->getDOTName() + ";\n" + children[i]->DOTGraphStringHelper();
|
||||
if (children[i] != NULL)
|
||||
ourDOTRelation += getDOTName() + " -> " + children[i]->getDOTName() + ";\n" + children[i]->DOTGraphStringHelper();
|
||||
else
|
||||
ourDOTRelation += getDOTName() + " -> BAD_NULL_" + getDOTName();
|
||||
}
|
||||
return(ourDOTRelation);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Parser.h"
|
||||
#include "Symbol.h"
|
||||
#include "GraphStructuredStack.h"
|
||||
#include "util.h"
|
||||
|
||||
class RNGLRParser: public Parser {
|
||||
public:
|
||||
@@ -19,21 +20,21 @@ class RNGLRParser: public Parser {
|
||||
private:
|
||||
void reducer(int i);
|
||||
void shifter(int i);
|
||||
void addChildren(NodeTree<Symbol*>* parent, std::vector<NodeTree<Symbol*>*> children, int nullablePartsIndex);
|
||||
void addChildren(NodeTree<Symbol*>* parent, std::vector<NodeTree<Symbol*>*>* children, int nullablePartsIndex);
|
||||
|
||||
void addStates(std::vector< State* >* stateSets, State* state);
|
||||
bool reducesToNull(ParseRule* rule);
|
||||
bool reducesToNull(ParseRule* rule, std::vector<Symbol*> avoidList);
|
||||
|
||||
bool belongsToFamily(NodeTree<Symbol*>* node, std::vector<NodeTree<Symbol*>*>* nodes);
|
||||
bool arePacked(std::vector<NodeTree<Symbol*>*>* nodes);
|
||||
bool arePacked(std::vector<NodeTree<Symbol*>*> nodes);
|
||||
bool isPacked(NodeTree<Symbol*>* node);
|
||||
void setPacked(NodeTree<Symbol*>* node, bool isPacked);
|
||||
|
||||
int getNullableIndex(ParseRule* rule);
|
||||
NodeTree<Symbol*> getNullableParts(ParseRule* rule);
|
||||
NodeTree<Symbol*> getNullableParts(Symbol* symbol);
|
||||
NodeTree<Symbol*> getNullableParts(int index);
|
||||
NodeTree<Symbol*>* getNullableParts(ParseRule* rule);
|
||||
NodeTree<Symbol*>* getNullableParts(Symbol* symbol);
|
||||
NodeTree<Symbol*>* getNullableParts(int index);
|
||||
|
||||
std::vector<NodeTree<Symbol*>*> getPathEdges(std::vector<NodeTree<int>*> path);
|
||||
|
||||
@@ -53,7 +54,7 @@ class RNGLRParser: public Parser {
|
||||
std::vector<std::pair<NodeTree<Symbol*>*, int> > SPPFStepNodes;
|
||||
|
||||
std::vector<NodeTree<Symbol*>*> nullableParts;
|
||||
std::map<NodeTree<Symbol*>*, bool> packedMap;
|
||||
std::map<NodeTree<Symbol*>, bool> packedMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user