#ifndef PARSER_H #define 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 #include #include #include #include #include class Parser { public: Parser(); ~Parser(); void loadGrammer(std::string grammerInputString); std::vector* firstSet(Symbol* token); void printFirstSets(); std::vector* incrementiveFollowSet(ParseRule* rule); 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; Lexer lexer; std::map symbols; std::vector loadedGrammer; std::vector< State* > stateSets; std::vector< std::vector* > table; std::vector symbolIndexVec; std::stack stateStack; std::stack symbolStack; Symbol* getOrAddSymbol(std::string symbolString, bool isTerminal); NodeTree* reduceTreeCombine(Symbol* newSymbol, std::vector &symbols); }; #endif