Problem was actually in grammer, fixed it. Also made identical rules with different lookahead merge. Now just started on creating parse trees. Stopping for night.

This commit is contained in:
Nathan Braswell
2013-08-06 01:49:45 -04:00
parent 9460bacf1c
commit 680d978dcb
9 changed files with 136 additions and 40 deletions

View File

@@ -28,9 +28,11 @@ class NodeTree {
std::vector<NodeTree<T>*> getParents();
void addChild(NodeTree<T>* child);
void addChildren(std::vector<NodeTree<T>*>* children);
int findChild(NodeTree<T>* child);
void removeChild(NodeTree<T>* child);
void removeChild(int index);
void clearChildren();
std::vector<NodeTree<T>*> getChildren();
NodeTree<T>* get(int index);
@@ -111,6 +113,12 @@ void NodeTree<T>::addChild(NodeTree<T>* child) {
children.push_back(child);
}
template<class T>
void NodeTree<T>::addChildren(std::vector<NodeTree<T>*>* children) {
for (std::vector<NodeTree<T>*>::size_type i = 0; i < children->size(); i++)
addChild((*children)[i]);
}
template<class T>
int NodeTree<T>::findChild(NodeTree<T>* child) {
for (int i = 0; i < children.size(); i++) {
@@ -135,6 +143,13 @@ void NodeTree<T>::removeChild(NodeTree<T>* child) {
}
}
template<class T>
void NodeTree<T>::clearChildren() {
for (std::vector<T>::size_type i = 0; i < children.size(); i++)
children[i] = NULL;
children.clear();
}
template<class T>
std::vector<NodeTree<T>*> NodeTree<T>::getChildren() {
return children;

View File

@@ -37,6 +37,7 @@ class ParseRule {
bool isAtEnd();
void setLookahead(std::vector<Symbol*>* lookahead);
void addLookahead(std::vector<Symbol*>* lookahead);
std::vector<Symbol*>* getLookahead();
std::string toString();

View File

@@ -1,3 +1,6 @@
#ifndef RNGLRPARSER_H
#define RNGLRPARSER_H
#include <iostream>
#include <queue>
#include "Parser.h"
@@ -8,16 +11,30 @@ class RNGLRParser: public Parser {
RNGLRParser();
~RNGLRParser();
NodeTree<Symbol*>* parseInput(std::string inputString);
private:
void reducer(int i);
void shifter(int i);
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);
private:
bool belongsToFamily(NodeTree<Symbol*>* node, std::vector<NodeTree<Symbol*>*>* nodes);
bool arePacked(std::vector<NodeTree<Symbol*>*>* nodes);
bool isPacked(NodeTree<Symbol*>* node);
void setPacked(NodeTree<Symbol*>* node, bool isPacked)
std::vector<Symbol*> input;
GraphStructuredStack gss;
//start node, lefthand side of the reduction, reduction length
std::queue<std::pair< std::pair<NodeTree<int>*, Symbol*>, int > > toReduce;
//Node coming from, state going to
std::queue< std::pair<NodeTree<int>*, int> > toShift;
std::vector<NodeTree<Symbol*>*> nullableParts;
std::map<NodeTree<Symbol*>*, bool> packedMap;
};
#endif