2013-05-20 19:34:15 -04:00
|
|
|
#ifndef PARSER_H
|
|
|
|
|
#define PARSER_H
|
|
|
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
|
#define NULL 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <vector>
|
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-05-24 00:00:41 -04:00
|
|
|
void createStateSet();
|
2013-05-26 22:12:47 -04:00
|
|
|
void closure(State* state);
|
|
|
|
|
void addState(std::vector< State* >* stateSets, State* state, Symbol*);
|
2013-05-24 00:00:41 -04:00
|
|
|
std::string stateSetToString();
|
2013-05-23 01:35:54 -04:00
|
|
|
int gotoTable(int state, Symbol* token);
|
|
|
|
|
ParseAction* actionTable(int state, Symbol* token);
|
|
|
|
|
void parseInput(std::string inputString);
|
|
|
|
|
|
2013-05-20 19:34:15 -04:00
|
|
|
std::string grammerToString();
|
2013-05-20 22:59:57 -04:00
|
|
|
std::string grammerToDOT();
|
2013-05-20 19:34:15 -04:00
|
|
|
private:
|
|
|
|
|
StringReader reader;
|
|
|
|
|
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-05-29 20:43:35 -04:00
|
|
|
//std::vector< std::vector<ParseAction*> >
|
|
|
|
|
|
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);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|