Have almost got the RNGLR recognizer. Something is wrong with the GSS, I think when it's built. It seems to sometimes have parents as children, or something.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "NodeTree<int>.h"
|
||||
#include <queue>
|
||||
#include "NodeTree.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifndef GRAPH_STRUCTURED_STACK
|
||||
#define GRAPH_STRUCTURED_STACK
|
||||
@@ -17,7 +19,10 @@ class GraphStructuredStack {
|
||||
std::vector<NodeTree<int>*>* getReachable(NodeTree<int>* start, int lenght);
|
||||
bool hasEdge(NodeTree<int>* start, NodeTree<int>* end);
|
||||
void addEdge(NodeTree<int>* start, NodeTree<int>* end);
|
||||
|
||||
std::string toString();
|
||||
private:
|
||||
std::vector<std::vector<NodeTree<int>*>*> gss;
|
||||
//
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,24 +2,7 @@
|
||||
#define LALRPARSER_H
|
||||
|
||||
#include "Parser.h"
|
||||
/*
|
||||
#include "util.h"
|
||||
#include "ParseRule.h"
|
||||
#include "ParseAction.h"
|
||||
#include "Symbol.h"
|
||||
#include "State.h"
|
||||
#include "StringReader.h"
|
||||
#include "Lexer.h"
|
||||
#include "NodeTree.h"
|
||||
#include "Table.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
*/
|
||||
class LALRParser: public Parser {
|
||||
public:
|
||||
LALRParser();
|
||||
|
||||
@@ -70,7 +70,6 @@ NodeTree<T>::NodeTree() {
|
||||
|
||||
template<class T>
|
||||
NodeTree<T>::NodeTree(std::string name, T inData) {
|
||||
data = NULL;
|
||||
this->name = name;
|
||||
this->data = inData;
|
||||
id = idCounter++;
|
||||
@@ -138,7 +137,7 @@ void NodeTree<T>::removeChild(NodeTree<T>* child) {
|
||||
|
||||
template<class T>
|
||||
std::vector<NodeTree<T>*> NodeTree<T>::getChildren() {
|
||||
return &children;
|
||||
return children;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
#include "Parser.h"
|
||||
#include "GraphStructuredStack.h"
|
||||
|
||||
class RNGLRParser {
|
||||
class RNGLRParser: public Parser {
|
||||
public:
|
||||
parseInput(std::string inputString);
|
||||
reducer(int i);
|
||||
shifter(int i);
|
||||
RNGLRParser();
|
||||
~RNGLRParser();
|
||||
NodeTree<Symbol*>* parseInput(std::string inputString);
|
||||
void reducer(int i);
|
||||
void shifter(int i);
|
||||
private:
|
||||
Lexer lexer;
|
||||
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;
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ class Symbol {
|
||||
Symbol(std::string name, bool isTerminal, NodeTree<Symbol*>* tree);
|
||||
~Symbol();
|
||||
bool const operator==(const Symbol &other);
|
||||
bool const operator!=(const Symbol &other);
|
||||
std::string getName();
|
||||
std::string toString();
|
||||
Symbol* clone();
|
||||
|
||||
@@ -14,6 +14,7 @@ class Table {
|
||||
void setSymbols(Symbol* EOFSymbol, Symbol* nullSymbol);
|
||||
void add(int stateNum, Symbol* tranSymbol, ParseAction* action);
|
||||
std::vector<ParseAction*>* get(int state, Symbol* token);
|
||||
ParseAction* getShift(int state, Symbol* token);
|
||||
std::string toString();
|
||||
private:
|
||||
std::vector< std::vector< std::vector<ParseAction*>* >* > table;
|
||||
|
||||
Reference in New Issue
Block a user