Fixed lots of bugs, added much more sane and efficient ParseAction table instead of recalculating every time. Fixed lots of bugs and inefficencies. Some temporary hacks in the table, mostly having to do with not having an EOF Symbol yet.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#include "util.h"
|
||||
#include "ParseRule.h"
|
||||
|
||||
#include <vector>
|
||||
@@ -17,6 +18,8 @@ class ParseAction {
|
||||
ParseAction(ActionType action, ParseRule* reduceRule);
|
||||
ParseAction(ActionType action, int shiftState);
|
||||
~ParseAction();
|
||||
bool const operator==(const ParseAction &other);
|
||||
bool const operator!=(const ParseAction &other);
|
||||
std::string toString();
|
||||
static std::string actionToString(ActionType action);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#include "util.h"
|
||||
#include "ParseRule.h"
|
||||
#include "ParseAction.h"
|
||||
#include "Symbol.h"
|
||||
@@ -27,14 +28,17 @@ class Parser {
|
||||
void loadGrammer(std::string grammerInputString);
|
||||
void createStateSet();
|
||||
void closure(State* state);
|
||||
void addState(std::vector< State* >* stateSets, State* state, Symbol*);
|
||||
void addStates(std::vector< State* >* stateSets, State* state);
|
||||
std::string stateSetToString();
|
||||
int gotoTable(int state, Symbol* token);
|
||||
ParseAction* actionTable(int state, Symbol* token);
|
||||
void addToTable(State* fromState, Symbol* tranSymbol, ParseAction* action);
|
||||
ParseAction* getTable(int state, Symbol* token);
|
||||
NodeTree* parseInput(std::string inputString);
|
||||
|
||||
std::string grammerToString();
|
||||
std::string grammerToDOT();
|
||||
|
||||
std::string tableToString();
|
||||
|
||||
private:
|
||||
StringReader reader;
|
||||
std::map<std::string, Symbol*> symbols;
|
||||
@@ -42,7 +46,8 @@ class Parser {
|
||||
|
||||
std::vector< State* > stateSets;
|
||||
|
||||
//std::vector< std::vector<ParseAction*> >
|
||||
std::vector< std::vector<ParseAction*>* > table;
|
||||
std::vector<Symbol*> symbolIndexVec;
|
||||
|
||||
std::stack<int> stateStack;
|
||||
std::stack<Symbol*> symbolStack;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#include "util.h"
|
||||
#include "ParseRule.h"
|
||||
|
||||
#include <vector>
|
||||
@@ -16,7 +17,6 @@ class State {
|
||||
public:
|
||||
State(int number, ParseRule* basis);
|
||||
~State();
|
||||
std::string intToString(int theInt);
|
||||
bool const operator==(const State &other);
|
||||
bool const operator!=(const State &other);
|
||||
std::vector<ParseRule*>* getBasis();
|
||||
|
||||
9
include/util.h
Normal file
9
include/util.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
std::string intToString(int theInt);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user