Added main loop of parser.
This commit is contained in:
28
include/ParseAction.h
Normal file
28
include/ParseAction.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef PARSE_ACTION_H
|
||||
#define PARSE_ACTION_H
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#include "ParseRule.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class ParseAction {
|
||||
public:
|
||||
enum ActionType { INVALID, REDUCE, SHIFT, ACCEPT, REJECT };
|
||||
ParseAction(ActionType action, ParseRule* reduceRule = NULL, int shiftState = 0);
|
||||
~ParseAction();
|
||||
std::string toString();
|
||||
static std::string actionToString(ActionType action);
|
||||
|
||||
ActionType action;
|
||||
ParseRule* reduceRule;
|
||||
int shiftState;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -22,6 +22,9 @@ class ParseRule {
|
||||
void setLeftHandle(Symbol* leftHandle);
|
||||
void appendToRight(Symbol* appendee);
|
||||
|
||||
Symbol* getLeftSide();
|
||||
std::vector<Symbol*> getRightSide();
|
||||
|
||||
bool advancePointer();
|
||||
|
||||
std::string toString();
|
||||
|
||||
@@ -6,11 +6,13 @@
|
||||
#endif
|
||||
|
||||
#include "ParseRule.h"
|
||||
#include "ParseAction.h"
|
||||
#include "Symbol.h"
|
||||
#include "StringReader.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
@@ -20,6 +22,10 @@ class Parser {
|
||||
~Parser();
|
||||
|
||||
void loadGrammer(std::string grammerInputString);
|
||||
int gotoTable(int state, Symbol* token);
|
||||
ParseAction* actionTable(int state, Symbol* token);
|
||||
void parseInput(std::string inputString);
|
||||
|
||||
std::string grammerToString();
|
||||
std::string grammerToDOT();
|
||||
private:
|
||||
@@ -27,6 +33,9 @@ class Parser {
|
||||
std::map<std::string, Symbol*> symbols;
|
||||
std::vector<ParseRule*> loadedGrammer;
|
||||
|
||||
std::stack<int> stateStack;
|
||||
std::stack<Symbol*> symbolStack;
|
||||
|
||||
Symbol* getOrAddSymbol(std::string symbolString, bool isTerminal);
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ class Symbol {
|
||||
public:
|
||||
Symbol(std::string name, bool isTerminal);
|
||||
~Symbol();
|
||||
bool const operator==(const Symbol &other);
|
||||
std::string toString();
|
||||
private:
|
||||
std::string name;
|
||||
|
||||
Reference in New Issue
Block a user