school/cs236/parser/predicate.h
2016-04-06 20:46:32 -07:00

84 lines
2.4 KiB
C++

#ifndef __PREDICATE_H__
#define __PREDICATE_H__
#include "parameter.h"
#include <vector>
#include <iostream>
using namespace std;
class predicate {
public:
string id;
vector<parameter> pred_list;
string toString() {
//schemes
stringstream s;
s << id << "(";
for(unsigned int i = 0; i < pred_list.size(); i++) {
s << pred_list[i].param;
if(i < pred_list.size()-1) {
s << ",";
}
}
s << ")\n";
return s.str();
}
string toString(bool a) {
//facts
stringstream s;
s << id << "(";
for(unsigned int i = 0; i < pred_list.size(); i++) {
s << "'" << pred_list[i].param << "'";
if(i < pred_list.size()-1) {
s << ",";
}
}
s << ").\n";
return s.str();
}
string toString(double a) {
//query
stringstream s;
s << id << "(";
for(unsigned int i = 0; i < pred_list.size(); i++) {
if(pred_list[i].type == "STRING") {
s << "'" << pred_list[i].param << "'";
if(i < pred_list.size()-1) {
s << ",";
}
}
if(pred_list[i].type == "ID") {
s << pred_list[i].param;
if(i < pred_list.size()-1) {
s << ",";
}
}
}
s << ")?\n";
return s.str();
}
string toString(int a) {
//rules
stringstream s;
s << id << "(";
for(unsigned int i = 0; i < pred_list.size(); i++) {
if(pred_list[i].type == "STRING") {
s << "'" << pred_list[i].param << "'";
if(i < pred_list.size()-1) {
s << ",";
}
}
if(pred_list[i].type == "ID") {
s << pred_list[i].param;
if(i < pred_list.size()-1) {
s << ",";
}
}
}
s << ")";
return s.str();
}
};
#endif