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>
|
2013-08-08 03:06:28 -04:00
|
|
|
#include <map>
|
2013-08-08 02:44:17 -04:00
|
|
|
#include <vector>
|
|
|
|
|
#include <algorithm>
|
2013-07-31 23:51:05 -04:00
|
|
|
#include "Parser.h"
|
2013-08-08 03:06:28 -04:00
|
|
|
#include "Symbol.h"
|
2013-07-31 23:51:05 -04:00
|
|
|
#include "GraphStructuredStack.h"
|
2013-08-09 04:39:43 -04:00
|
|
|
#include "util.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();
|
2013-10-02 03:15:20 -04:00
|
|
|
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-10-02 03:15:20 -04:00
|
|
|
void addChildren(NodeTree<Symbol>* parent, std::vector<NodeTree<Symbol>*>* children, NodeTree<Symbol>* nullableParts);
|
2013-08-06 01:49:45 -04:00
|
|
|
|
2013-08-22 15:41:30 -04:00
|
|
|
void addStates(std::vector< State* >* stateSets, State* state, std::queue<State*>* toDo);
|
2013-08-16 00:03:26 -04:00
|
|
|
void addStateReductionsToTable(State* state);
|
2013-08-13 14:01:53 -04:00
|
|
|
bool fullyReducesToNull(ParseRule* rule);
|
2013-08-02 15:21:42 -04:00
|
|
|
bool reducesToNull(ParseRule* rule);
|
2013-10-02 03:15:20 -04:00
|
|
|
bool reducesToNull(ParseRule* rule, std::vector<Symbol> avoidList);
|
2013-08-06 01:49:45 -04:00
|
|
|
|
2013-10-02 03:15:20 -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-08-08 02:44:17 -04:00
|
|
|
|
2013-10-02 03:15:20 -04:00
|
|
|
NodeTree<Symbol>* getNullableParts(ParseRule* rule);
|
|
|
|
|
NodeTree<Symbol>* getNullableParts(ParseRule* rule, std::vector<NodeTree<Symbol>*> avoidList);
|
|
|
|
|
NodeTree<Symbol>* getNullableParts(Symbol symbol);
|
2013-08-08 02:44:17 -04:00
|
|
|
|
2013-10-02 03:15:20 -04:00
|
|
|
std::vector<NodeTree<Symbol>*> getPathEdges(std::vector<NodeTree<int>*> path);
|
2013-08-06 01:49:45 -04:00
|
|
|
|
2013-10-02 03:15:20 -04:00
|
|
|
std::vector<Symbol> input;
|
2013-07-28 19:45:08 -04:00
|
|
|
GraphStructuredStack gss;
|
|
|
|
|
//start node, lefthand side of the reduction, reduction length
|
2013-08-08 02:44:17 -04:00
|
|
|
struct Reduction {
|
|
|
|
|
NodeTree<int>* from;
|
2013-10-02 03:15:20 -04:00
|
|
|
Symbol symbol;
|
2013-08-08 02:44:17 -04:00
|
|
|
int length;
|
2013-10-02 03:15:20 -04:00
|
|
|
NodeTree<Symbol>* nullableParts;
|
|
|
|
|
NodeTree<Symbol>* label;
|
2013-08-08 02:44:17 -04:00
|
|
|
} ;
|
2013-08-08 03:06:28 -04:00
|
|
|
std::queue<Reduction> 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-10-02 03:15:20 -04:00
|
|
|
std::vector<std::pair<NodeTree<Symbol>*, int> > SPPFStepNodes;
|
2013-08-06 01:49:45 -04:00
|
|
|
|
2013-10-02 03:15:20 -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
|