2013-05-20 19:34:15 -04:00
|
|
|
#ifndef PARSER_H
|
|
|
|
|
#define PARSER_H
|
|
|
|
|
|
2013-06-04 19:50:16 -04:00
|
|
|
#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"
|
2013-05-26 22:12:47 -04:00
|
|
|
#include "State.h"
|
2013-05-20 19:34:15 -04:00
|
|
|
#include "StringReader.h"
|
2013-06-13 14:25:10 -04:00
|
|
|
#include "Lexer.h"
|
2013-05-30 19:49:19 -04:00
|
|
|
#include "NodeTree.h"
|
2013-07-16 11:15:58 -04:00
|
|
|
#include "Table.h"
|
2013-05-20 19:34:15 -04:00
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <vector>
|
2013-05-30 19:49:19 -04:00
|
|
|
#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);
|
2013-06-13 19:11:31 -04:00
|
|
|
std::vector<Symbol*>* firstSet(Symbol* token);
|
2013-07-10 23:50:53 -04:00
|
|
|
std::vector<Symbol*>* firstSet(Symbol* token, std::vector<Symbol*> &avoidList);
|
2013-06-26 14:27:28 -04:00
|
|
|
std::vector<Symbol*>* incrementiveFollowSet(ParseRule* rule);
|
2013-05-24 00:00:41 -04:00
|
|
|
void createStateSet();
|
2013-05-26 22:12:47 -04:00
|
|
|
void closure(State* state);
|
2013-06-04 19:50:16 -04:00
|
|
|
void addStates(std::vector< State* >* stateSets, State* state);
|
2013-07-16 11:15:58 -04:00
|
|
|
int stateNum(State* state);
|
2013-05-24 00:00:41 -04:00
|
|
|
std::string stateSetToString();
|
2013-07-16 11:15:58 -04:00
|
|
|
|
2013-07-28 19:45:08 -04:00
|
|
|
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();
|
2013-05-20 22:59:57 -04:00
|
|
|
std::string grammerToDOT();
|
2013-06-04 19:50:16 -04:00
|
|
|
|
|
|
|
|
std::string tableToString();
|
|
|
|
|
|
2013-05-20 19:34:15 -04:00
|
|
|
private:
|
|
|
|
|
StringReader reader;
|
2013-07-02 01:47:42 -04:00
|
|
|
Lexer lexer;
|
2013-05-20 19:34:15 -04:00
|
|
|
std::map<std::string, Symbol*> symbols;
|
|
|
|
|
std::vector<ParseRule*> loadedGrammer;
|
|
|
|
|
|
2013-05-26 22:12:47 -04:00
|
|
|
std::vector< State* > stateSets;
|
2013-05-24 00:00:41 -04:00
|
|
|
|
2013-07-09 02:45:59 -04:00
|
|
|
//The EOFSymbol, a pointer because of use in table, etc
|
|
|
|
|
Symbol* EOFSymbol;
|
|
|
|
|
//The nullSymbol, ditto with above. Also used in comparisons
|
|
|
|
|
Symbol* nullSymbol;
|
|
|
|
|
|
2013-07-16 11:15:58 -04:00
|
|
|
Table table;
|
|
|
|
|
|
2013-05-29 20:43:35 -04:00
|
|
|
|
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);
|
2013-07-28 19:45:08 -04:00
|
|
|
NodeTree<Symbol*>* reduceTreeCombine(Symbol* newSymbol, std::vector<Symbol*> &symbols);
|
2013-05-20 19:34:15 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|