2013-08-06 01:49:45 -04:00
|
|
|
#ifndef RNGLRPARSER_H
|
|
|
|
|
#define RNGLRPARSER_H
|
|
|
|
|
|
2013-07-28 19:45:08 -04:00
|
|
|
#include <iostream>
|
2013-07-31 23:51:05 -04:00
|
|
|
#include <queue>
|
|
|
|
|
#include "Parser.h"
|
|
|
|
|
#include "GraphStructuredStack.h"
|
2013-07-28 19:45:08 -04:00
|
|
|
|
2013-07-31 23:51:05 -04:00
|
|
|
class RNGLRParser: public Parser {
|
2013-07-28 19:45:08 -04:00
|
|
|
public:
|
2013-07-31 23:51:05 -04:00
|
|
|
RNGLRParser();
|
|
|
|
|
~RNGLRParser();
|
|
|
|
|
NodeTree<Symbol*>* parseInput(std::string inputString);
|
2013-08-06 01:49:45 -04:00
|
|
|
|
|
|
|
|
private:
|
2013-07-31 23:51:05 -04:00
|
|
|
void reducer(int i);
|
|
|
|
|
void shifter(int i);
|
2013-08-06 01:49:45 -04:00
|
|
|
void addChildren(NodeTree<Symbol*>* parent, std::vector<NodeTree<Symbol*>*> children, int nullablePartsIndex);
|
|
|
|
|
|
2013-08-02 02:47:01 -04:00
|
|
|
void addStates(std::vector< State* >* stateSets, State* state);
|
2013-08-02 15:21:42 -04:00
|
|
|
bool reducesToNull(ParseRule* rule);
|
|
|
|
|
bool reducesToNull(ParseRule* rule, std::vector<Symbol*> avoidList);
|
2013-08-06 01:49:45 -04:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2013-07-28 19:45:08 -04:00
|
|
|
std::vector<Symbol*> input;
|
|
|
|
|
GraphStructuredStack gss;
|
|
|
|
|
//start node, lefthand side of the reduction, reduction length
|
2013-07-31 23:51:05 -04:00
|
|
|
std::queue<std::pair< std::pair<NodeTree<int>*, Symbol*>, int > > toReduce;
|
2013-07-28 19:45:08 -04:00
|
|
|
//Node coming from, state going to
|
2013-07-28 23:48:10 -04:00
|
|
|
std::queue< std::pair<NodeTree<int>*, int> > toShift;
|
2013-08-06 01:49:45 -04:00
|
|
|
|
|
|
|
|
std::vector<NodeTree<Symbol*>*> nullableParts;
|
|
|
|
|
std::map<NodeTree<Symbol*>*, bool> packedMap;
|
2013-07-28 19:45:08 -04:00
|
|
|
};
|
2013-08-06 01:49:45 -04:00
|
|
|
|
|
|
|
|
#endif
|