Files
kraken/include/Parser.h

66 lines
1.5 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"
#include "Table.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);
std::vector<Symbol*>* incrementiveFollowSet(ParseRule* rule);
void createStateSet();
void closure(State* state);
void addStates(std::vector< State* >* stateSets, State* state);
int stateNum(State* state);
std::string stateSetToString();
NodeTree<Symbol*>* 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;
Table table;
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<Symbol*>* reduceTreeCombine(Symbol* newSymbol, std::vector<Symbol*> &symbols);
2013-05-20 19:34:15 -04:00
};
#endif