Made Symbol always stack, not heap, allocated. Finally fixed bugs with ASTTransformation.
This commit is contained in:
@@ -7,14 +7,14 @@ LALRParser::~LALRParser() {
|
||||
//Nothing to do in this version
|
||||
}
|
||||
|
||||
NodeTree<Symbol*>* LALRParser::parseInput(std::string inputString) {
|
||||
NodeTree<Symbol>* LALRParser::parseInput(std::string inputString) {
|
||||
lexer.setInput(inputString);
|
||||
Symbol* token = lexer.next();
|
||||
Symbol token = lexer.next();
|
||||
std::vector<ParseAction*>* actionList;
|
||||
ParseAction* action;
|
||||
|
||||
stateStack.push(0);
|
||||
symbolStack.push(new Symbol("INVALID", false));
|
||||
symbolStack.push(Symbol("INVALID", false));
|
||||
|
||||
while (true) {
|
||||
std::cout << "In state: " << intToString(stateStack.top()) << std::endl;
|
||||
@@ -28,18 +28,18 @@ NodeTree<Symbol*>* LALRParser::parseInput(std::string inputString) {
|
||||
|
||||
int rightSideLength = action->reduceRule->getRightSide().size();
|
||||
//Keep track of symbols popped for parse tree
|
||||
std::vector<Symbol*> poppedSymbols;
|
||||
std::vector<Symbol> poppedSymbols;
|
||||
for (int i = 0; i < rightSideLength; i++) {
|
||||
poppedSymbols.push_back(symbolStack.top());
|
||||
stateStack.pop();
|
||||
symbolStack.pop();
|
||||
}
|
||||
std::reverse(poppedSymbols.begin(), poppedSymbols.end()); //To put in order
|
||||
//Assign the new tree to the new Symbol
|
||||
Symbol* newSymbol = action->reduceRule->getLeftSide()->clone();
|
||||
newSymbol->setSubTree(reduceTreeCombine(newSymbol, poppedSymbols));
|
||||
//Assign the new tree to the Symbol
|
||||
Symbol newSymbol = action->reduceRule->getLeftSide();
|
||||
newSymbol.setSubTree(reduceTreeCombine(newSymbol, poppedSymbols));
|
||||
symbolStack.push(newSymbol);
|
||||
std::cout << "top of state is " << intToString(stateStack.top()) << " symbolStack top is " << symbolStack.top()->toString() << std::endl;
|
||||
std::cout << "top of state is " << intToString(stateStack.top()) << " symbolStack top is " << symbolStack.top().toString() << std::endl;
|
||||
|
||||
actionList = table.get(stateStack.top(), symbolStack.top());
|
||||
action = (*(actionList))[actionList->size()-1];
|
||||
@@ -50,7 +50,7 @@ NodeTree<Symbol*>* LALRParser::parseInput(std::string inputString) {
|
||||
break;
|
||||
}
|
||||
case ParseAction::SHIFT:
|
||||
std::cout << "Shift " << token->toString() << std::endl;
|
||||
std::cout << "Shift " << token.toString() << std::endl;
|
||||
|
||||
symbolStack.push(token);
|
||||
token = lexer.next();
|
||||
@@ -58,11 +58,11 @@ NodeTree<Symbol*>* LALRParser::parseInput(std::string inputString) {
|
||||
break;
|
||||
case ParseAction::ACCEPT:
|
||||
std::cout << "ACCEPTED!" << std::endl;
|
||||
return(symbolStack.top()->getSubTree());
|
||||
return(symbolStack.top().getSubTree());
|
||||
break;
|
||||
case ParseAction::REJECT:
|
||||
std::cout << "REJECTED!" << std::endl;
|
||||
std::cout << "REJECTED Symbol was " << token->toString() << std::endl;
|
||||
std::cout << "REJECTED Symbol was " << token.toString() << std::endl;
|
||||
return(NULL);
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user