2013-05-23 01:35:54 -04:00
|
|
|
#include "ParseAction.h"
|
|
|
|
|
|
2013-05-29 20:43:35 -04:00
|
|
|
ParseAction::ParseAction(ActionType action) {
|
|
|
|
|
this->action = action;
|
|
|
|
|
this->reduceRule = NULL;
|
|
|
|
|
this->shiftState = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParseAction::ParseAction(ActionType action, ParseRule* reduceRule) {
|
2013-05-23 01:35:54 -04:00
|
|
|
this->action = action;
|
|
|
|
|
this->reduceRule = reduceRule;
|
2013-05-29 20:43:35 -04:00
|
|
|
this->shiftState = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParseAction::ParseAction(ActionType action, int shiftState) {
|
|
|
|
|
this->action = action;
|
|
|
|
|
this->reduceRule = NULL;
|
2013-05-23 01:35:54 -04:00
|
|
|
this->shiftState = shiftState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParseAction::~ParseAction() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 23:50:53 -04:00
|
|
|
const bool ParseAction::equalsExceptLookahead(const ParseAction &other) {
|
|
|
|
|
return( action == other.action && ( reduceRule == other.reduceRule || reduceRule->equalsExceptLookahead(*(other.reduceRule)) ) && shiftState == other.shiftState);
|
|
|
|
|
}
|
2013-06-04 19:50:16 -04:00
|
|
|
|
|
|
|
|
const bool ParseAction::operator==(const ParseAction &other) {
|
|
|
|
|
return( action == other.action && ( reduceRule == other.reduceRule || *reduceRule == *(other.reduceRule) ) && shiftState == other.shiftState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool ParseAction::operator!=(const ParseAction &other) {
|
|
|
|
|
return !(this->operator==(other));
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-23 01:35:54 -04:00
|
|
|
std::string ParseAction::actionToString(ActionType action) {
|
|
|
|
|
switch (action) {
|
|
|
|
|
case REDUCE:
|
|
|
|
|
return "reduce";
|
|
|
|
|
break;
|
|
|
|
|
case SHIFT:
|
|
|
|
|
return "shift";
|
|
|
|
|
break;
|
|
|
|
|
case ACCEPT:
|
|
|
|
|
return "accept";
|
|
|
|
|
break;
|
|
|
|
|
case REJECT:
|
|
|
|
|
return "reject";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string ParseAction::toString() {
|
2013-06-04 19:50:16 -04:00
|
|
|
std::string outputString = "";
|
|
|
|
|
outputString += actionToString(action);
|
|
|
|
|
if (reduceRule != NULL)
|
|
|
|
|
outputString += " " + reduceRule->toString();
|
|
|
|
|
if (shiftState != -1)
|
|
|
|
|
outputString += " " + intToString(shiftState);
|
2013-05-23 01:35:54 -04:00
|
|
|
return(outputString);
|
|
|
|
|
}
|