Cleaned up some debug messages, parseInput(string) now returns a parse tree of NodeTree*. This is done by having each non-terminal Symbol have it's own subtree and calling a method to combine subtrees and terminals on each reduce. The output is now the DOT version of the parse tree.

This commit is contained in:
Nathan Braswell
2013-05-30 19:49:19 -04:00
parent dd7b255520
commit 0c4af245bf
5 changed files with 85 additions and 28 deletions

View File

@@ -2,7 +2,14 @@
Symbol::Symbol(std::string name, bool isTerminal) {
this->name = name;
this->isTerminal = isTerminal;
this->terminal = isTerminal;
this->subTree = NULL;
}
Symbol::Symbol(std::string name, bool isTerminal, NodeTree* tree) {
this->name = name;
this->terminal = isTerminal;
this->subTree = tree;
}
Symbol::~Symbol() {
@@ -10,10 +17,26 @@ Symbol::~Symbol() {
}
const bool Symbol::operator==(const Symbol &other) {
return( name == other.name && isTerminal == other.isTerminal);
return( name == other.name && terminal == other.terminal);
}
std::string Symbol::toString() {
return(name + "(" + (isTerminal ? "T" : "NT") + ")");
return(name); //+ "(" + (terminal ? "T" : "NT") + ")");
}
Symbol* Symbol::clone() {
return new Symbol(name, terminal, subTree);
}
void Symbol::setSubTree(NodeTree* tree) {
subTree = tree;
}
NodeTree* Symbol::getSubTree() {
return subTree;
}
bool Symbol::isTerminal() {
return terminal;
}