#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <cmath>
//disables any deprecation warning
#pragma warning(disable : 4996)
//usings
using std::vector;
using std::string;
using std::cout;
using std::endl;
using std::stringstream;
bool try_parse(const std::string& s)
{
char* end = 0;
double val = strtod(s.c_str(), &end);
return end != s.c_str() && val != HUGE_VAL;
}
char first_char(string str) {
return *str.c_str();
}
vector<string> tok_type(vector<string> vec) {
for (int i = 0; i < vec.size(); i++) {
string &s = vec[i];
bool doubly = try_parse(s);
bool amp = first_char(s) == '&';
if (!doubly && !amp) {
s = "<unknown> " + s;
continue;
}
else if (!doubly && amp) {
s = "<operator> " + s;
continue;
}
else if (doubly && !amp) {
s = "<double> " + s;
continue;
}
}
return vec;
}
long double parse(string str) {
return std::stold(str);
}
vector<string> split(string str, string token = " ") {
vector<string>result;
while (str.size()) {
int index = str.find(token);
if (index != string::npos) {
result.push_back(str.substr(0, index));
str = str.substr(index + token.size());
if (str.size() == 0)result.push_back(str);
}
else {
result.push_back(str);
str = "";
}
}
return result;
}
string simplify(string expr) {
string iexpr = expr;
for (int i = 0; i < iexpr.length(); i++) {
char& c = iexpr[i];
if (c == '+')
iexpr.replace(i, 1, " &ad ");
else if (c == '-')
iexpr.replace(i, 1, " &sb ");
else if (c == '*')
iexpr.replace(i, 1, " &mp ");
else if (c == '/')
iexpr.replace(i, 1, " &dv ");
}
return iexpr;
}
int main() {
vector<string> sep_rep = tok_type(split(simplify("21+32-3*2")));
for (auto str : sep_rep) {
cout << str << endl;
}
std::cin.get();
return 0;
}