Files
kraken/include/Parser.h

66 lines
1.7 KiB
C
Raw Normal View History

2013-05-20 19:34:15 -04:00
#ifndef PARSER_H
#define PARSER_H
#include "util.h"
2013-05-20 19:34:15 -04:00
#include "ParseRule.h"
2013-05-23 01:35:54 -04:00
#include "ParseAction.h"
2013-05-20 19:34:15 -04:00
#include "Symbol.h"
#include "State.h"
2013-05-20 19:34:15 -04:00
#include "StringReader.h"
#include "Lexer.h"
#include "NodeTree.h"
2013-05-20 19:34:15 -04:00
#include <map>
#include <vector>
#include <algorithm>
2013-05-23 01:35:54 -04:00
#include <stack>
2013-05-20 19:34:15 -04:00
#include <string>
#include <iostream>
class Parser {
public:
Parser();
~Parser();
void loadGrammer(std::string grammerInputString);
std::vector<Symbol*>* firstSet(Symbol* token);
std::vector<Symbol*>* firstSet(Symbol* token, std::vector<Symbol*> &avoidList);
void printFirstSets();
std::vector<Symbol*>* 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);
2013-05-23 01:35:54 -04:00
2013-05-20 19:34:15 -04:00
std::string grammerToString();
std::string grammerToDOT();
std::string tableToString();
2013-05-20 19:34:15 -04:00
private:
StringReader reader;
Lexer lexer;
2013-05-20 19:34:15 -04:00
std::map<std::string, Symbol*> symbols;
std::vector<ParseRule*> loadedGrammer;
std::vector< State* > stateSets;
//The EOFSymbol, a pointer because of use in table, etc
Symbol* EOFSymbol;
//The nullSymbol, ditto with above. Also used in comparisons
Symbol* nullSymbol;
std::vector< std::vector<ParseAction*>* > table;
std::vector<Symbol*> symbolIndexVec;
2013-05-23 01:35:54 -04:00
std::stack<int> stateStack;
std::stack<Symbol*> symbolStack;
2013-05-20 19:34:15 -04:00
Symbol* getOrAddSymbol(std::string symbolString, bool isTerminal);
NodeTree* reduceTreeCombine(Symbol* newSymbol, std::vector<Symbol*> &symbols);
2013-05-20 19:34:15 -04:00
};
#endif