Files
kraken/include/Parser.h

59 lines
1.3 KiB
C++

#ifndef PARSER_H
#define PARSER_H
#ifndef NULL
#define NULL 0
#endif
#include "util.h"
#include "ParseRule.h"
#include "ParseAction.h"
#include "Symbol.h"
#include "State.h"
#include "StringReader.h"
#include "NodeTree.h"
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <iostream>
class Parser {
public:
Parser();
~Parser();
void loadGrammer(std::string grammerInputString);
void createStateSet();
void closure(State* state);
void addStates(std::vector< State* >* stateSets, State* state);
std::string stateSetToString();
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;
std::vector<ParseRule*> loadedGrammer;
std::vector< State* > stateSets;
std::vector< std::vector<ParseAction*>* > table;
std::vector<Symbol*> symbolIndexVec;
std::stack<int> stateStack;
std::stack<Symbol*> symbolStack;
Symbol* getOrAddSymbol(std::string symbolString, bool isTerminal);
NodeTree* reduceTreeCombine(Symbol* newSymbol, std::vector<Symbol*> &symbols);
};
#endif