Have a nullableParts generator now. It works for simple cases and may work for advanced cases, but more testing is required to ensure full usability.

This commit is contained in:
Nathan Braswell
2013-08-13 14:01:53 -04:00
parent 3a5d94caaa
commit d21f521266
3 changed files with 58 additions and 29 deletions

View File

@@ -45,7 +45,7 @@ class NodeTree {
std::string DOTGraphString();
private:
std::string DOTGraphStringHelper();
std::string DOTGraphStringHelper(std::vector<NodeTree<T>*> avoidList);
std::string getDOTName();
std::string name;
T data;
@@ -124,6 +124,8 @@ std::vector<NodeTree<T>*> NodeTree<T>::getParents() {
template<class T>
void NodeTree<T>::addChild(NodeTree<T>* child) {
if (!child)
throw "Help, NULL child";
if (findChild(child) == -1)
children.push_back(child);
}
@@ -206,15 +208,20 @@ void NodeTree<T>::setData(T data) {
template<class T>
std::string NodeTree<T>::DOTGraphString() {
return( "digraph Kraken { \n" + DOTGraphStringHelper() + "}");
return( "digraph Kraken { \n" + DOTGraphStringHelper(std::vector<NodeTree<T>*>()) + "}");
}
template<class T>
std::string NodeTree<T>::DOTGraphStringHelper() {
std::string NodeTree<T>::DOTGraphStringHelper(std::vector<NodeTree<T>*> avoidList) {
for (typename std::vector<NodeTree<T>*>::size_type i = 0; i < avoidList.size(); i++)
if (this == avoidList[i])
return "";
avoidList.push_back(this);
std::string ourDOTRelation = "";
for (int i = 0; i < children.size(); i++) {
if (children[i] != NULL)
ourDOTRelation += getDOTName() + " -> " + children[i]->getDOTName() + ";\n" + children[i]->DOTGraphStringHelper();
ourDOTRelation += getDOTName() + " -> " + children[i]->getDOTName() + ";\n" + children[i]->DOTGraphStringHelper(avoidList);
else
ourDOTRelation += getDOTName() + " -> BAD_NULL_" + getDOTName() + "\n";
}

View File

@@ -23,6 +23,7 @@ class RNGLRParser: public Parser {
void addChildren(NodeTree<Symbol*>* parent, std::vector<NodeTree<Symbol*>*>* children, NodeTree<Symbol*>* nullableParts);
void addStates(std::vector< State* >* stateSets, State* state);
bool fullyReducesToNull(ParseRule* rule);
bool reducesToNull(ParseRule* rule);
bool reducesToNull(ParseRule* rule, std::vector<Symbol*> avoidList);
@@ -32,6 +33,7 @@ class RNGLRParser: public Parser {
void setPacked(NodeTree<Symbol*>* node, bool isPacked);
NodeTree<Symbol*>* getNullableParts(ParseRule* rule);
NodeTree<Symbol*>* getNullableParts(ParseRule* rule, std::vector<NodeTree<Symbol*>*> avoidList);
NodeTree<Symbol*>* getNullableParts(Symbol* symbol);
std::vector<NodeTree<Symbol*>*> getPathEdges(std::vector<NodeTree<int>*> path);