Files
kraken/include/Parser.h

74 lines
1.8 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
2013-08-22 15:41:30 -04:00
#include <queue>
#include <set>
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();
virtual void loadGrammer(std::string grammerInputString);
virtual void createStateSet();
virtual std::string stateSetToString();
virtual NodeTree<Symbol>* parseInput(std::string inputString, std::string filename) = 0; // filename for error reporting
virtual std::string grammerToString();
virtual std::string grammerToDOT();
std::string tableToString();
void exportTable(std::ofstream &file);
void importTable(char* tableData);
protected:
std::vector<Symbol> firstSet(Symbol token, std::vector<Symbol> avoidList = std::vector<Symbol>(), bool addNewTokens = true);
bool isNullable(Symbol token);
bool isNullableHelper(Symbol token, std::set<Symbol> done);
std::map<Symbol, std::vector<Symbol>> tokenFirstSet;
std::map<Symbol, bool> tokenNullable;
std::vector<Symbol> incrementiveFollowSet(ParseRule* rule);
virtual void closure(State* state);
2013-08-22 15:41:30 -04:00
virtual void addStates(std::vector< State* >* stateSets, State* state, std::queue<State*>* toDo);
int stateNum(State* state);
2013-05-20 19:34:15 -04:00
StringReader reader;
Lexer lexer;
std::map<std::pair<std::string, bool>, Symbol> symbols;
2013-05-20 19:34:15 -04:00
std::vector<ParseRule*> loadedGrammer;
std::vector< State* > stateSets;
Symbol EOFSymbol;
Symbol nullSymbol;
Symbol invalidSymbol;
Table table;
2013-05-23 01:35:54 -04:00
std::stack<int> stateStack;
std::stack<Symbol> symbolStack;
2013-05-23 01:35:54 -04:00
Symbol getOrAddSymbol(std::string symbolString, bool isTerminal);
2013-05-20 19:34:15 -04:00
};
#endif