Cleaned up some debug messages, parseInput(string) now returns a parse tree of NodeTree*. This is done by having each non-terminal Symbol have it's own subtree and calling a method to combine subtrees and terminals on each reduce. The output is now the DOT version of the parse tree.
This commit is contained in:
@@ -10,9 +10,11 @@
|
||||
#include "Symbol.h"
|
||||
#include "State.h"
|
||||
#include "StringReader.h"
|
||||
#include "NodeTree.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
@@ -29,7 +31,7 @@ class Parser {
|
||||
std::string stateSetToString();
|
||||
int gotoTable(int state, Symbol* token);
|
||||
ParseAction* actionTable(int state, Symbol* token);
|
||||
void parseInput(std::string inputString);
|
||||
NodeTree* parseInput(std::string inputString);
|
||||
|
||||
std::string grammerToString();
|
||||
std::string grammerToDOT();
|
||||
@@ -46,6 +48,7 @@ class Parser {
|
||||
std::stack<Symbol*> symbolStack;
|
||||
|
||||
Symbol* getOrAddSymbol(std::string symbolString, bool isTerminal);
|
||||
NodeTree* reduceTreeCombine(Symbol* newSymbol, std::vector<Symbol*> &symbols);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -5,18 +5,26 @@
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#include "NodeTree.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class Symbol {
|
||||
public:
|
||||
Symbol(std::string name, bool isTerminal);
|
||||
Symbol(std::string name, bool isTerminal, NodeTree* tree);
|
||||
~Symbol();
|
||||
bool const operator==(const Symbol &other);
|
||||
std::string toString();
|
||||
Symbol* clone();
|
||||
void setSubTree(NodeTree* tree);
|
||||
NodeTree* getSubTree();
|
||||
bool isTerminal();
|
||||
private:
|
||||
std::string name;
|
||||
bool isTerminal;
|
||||
bool terminal;
|
||||
NodeTree* subTree;
|
||||
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user