Cnle7.0/2025.3.30
#include <iostream>
#include <map>
#include <string>
#include <iomanip>
#include <cmath>
#include <stdexcept>
#include <queue>
#include <stack>
#include <windows.h>
#include <fstream>
#define NONE_ERR 0
#define OPR_NOT_TYPE 1
#define DEF_NOT_DEFINE 2
#define DEF_IS_DEFINED 3
#define LET_ERROR 4
#define TO_ERROR 5
#define PRINT_TYPE_ERROR 6
#define DEF_TYPE_ERROR 7
#define TYPE_NOT_INT 8
#define TYPE_NOT_STR 9
#define TYPE_NOT_DOUBLE 10
#define QUEUE_ERROR 11
#define STACK_ERROR 12
#define FILE_NOT_DEF 13
#define FILE_ERROR 14
#define UNKNOW_ERROR 100000
using namespace std;
typedef const int IS_CNLE_ERROR;
void end_cnle(IS_CNLE_ERROR ERR) {
std::cout << "--------------------------------\n";
std::cout << "This program is return.";
switch (ERR) {
case NONE_ERR:
std::cout << "This program is return.No error.";
break;
case OPR_NOT_TYPE:
std::cout << "[error]The opr is not the type.";
break;
case DEF_NOT_DEFINE:
std::cout << "[error]The def is not define!";
break;
case DEF_IS_DEFINED:
std::cout << "[error]The def was defined!";
break;
case LET_ERROR:
std::cout << "[error]The let was error.";
break;
case TO_ERROR:
std::cout << "[error]The to was error.";
break;
case PRINT_TYPE_ERROR:
std::cout << "[error]The print type was not a type.";
break;
case DEF_TYPE_ERROR:
std::cout << "[error]The def type was not a type.";
break;
case TYPE_NOT_INT:
std::cout << "[error]The def type was not int.";
break;
case TYPE_NOT_STR:
std::cout << "[error]The def type was not string.";
break;
case TYPE_NOT_DOUBLE:
std::cout << "[error]The def type was not double.";
break;
case STACK_ERROR:
std::cout << "[error]The stack was error.";
break;
case QUEUE_ERROR:
std::cout << "[error]The queue was error.";
break;
case FILE_NOT_DEF:
std::cout << "[error]The file is not define.";
break;
case FILE_ERROR:
std::cout << "[error]The file is error.";
break;
default:
std::cout << "[error]unkown error";
break;
}
std::cout << "\nPut the keyboard to continue. . .";
}
std::string operator*(std::string __a, int __b) {
if (!__b) {
return "";
}
std::string ___ans = "";
for (int ___it = 1; ___it <= __b; ___it++) {
___ans += __a;
}
return ___ans;
}
void operator*=(std::string &__a, int __b) {
std::string ___ans = "";
for (int ___it = 1; ___it <= __b; ___it++) {
___ans += __a;
}
__a = ___ans;
}
std::string operator/(std::string __a, int __b) {
std::string ___ans = "";
int ___len = __a.size() / __b;
for (int ___it = 0; ___it < ___len; ___it++) {
___ans += __a[___it];
}
return ___ans;
}
void operator/=(std::string &__a, int __b) {
std::string ___ans = "";
int ___len = __a.size() / __b;
for (int ___it = 0; ___it < ___len; ___it++) {
___ans += __a[___it];
}
__a = ___ans;
}
void SetConsoleColor(WORD attributes) {
HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsoleOutput, attributes);
}
#define set_out SetConsoleColor(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN)
#define set_in SetConsoleColor(FOREGROUND_RED | FOREGROUND_BLUE);
struct nodef {
int d;
double lf;
string s;
string type;
string type_sq;
};
map<string, nodef> def;
map<string, queue<int>> qi_def;
map<string, stack<int>> si_def;
map<string, queue<string>> qs_def;
map<string, stack<string>> ss_def;
map<string, queue<double>> qd_def;
map<string, stack<double>> sd_def;
int retnum;
string fopr;//the first operator
const string out = "out<<< ", in = "in>>> ";
inline int Fib(int __x) {
if (__x == 1) {
return 1;
} else if (__x == 2) {
return 2;
}
int ___a_number__ = 1, ___b_number__ = 2, ___c_number__;
for (int i = 3; i <= __x; i++) {
___c_number__ = ___a_number__ + ___b_number__;
___a_number__ = ___b_number__;
___b_number__ = ___c_number__;
}
return ___b_number__;
}
inline is_prime(int in) {
if (in == 2) {
return true;
}
if (in == 0 || in == 1 || in % 2 == 0) {
return false;
}
for (int i = 3; i * i <= in; i += 2) {
if (!(in % i)) {
return false;
}
}
return true;
}
std::string btstr(bool in__bo) {
return (in__bo) ? "True" : "False";
}
double double_value(std::string name) {
return def[name].lf;
}
int int_value(std::string name) {
return def[name].d;
}
std::string str_value(std::string name) {
return def[name].s;
}
std::string deftype(std::string name) {
return def[name].type;
}
bool isopr(std::string __in) {
return (__in == fopr);
}
bool pd_is(int a, int b, std::string opr_is) {
if (opr_is == "bigger_than" || opr_is == ">") {
return (a > b);
}
if (opr_is == "smaller_than" || opr_is == "<") {
return (a < b);
}
if (opr_is == "equal_to" || opr_is == "==") {
return (a == b);
}
if (opr_is == "bigger_equal_to" || opr_is == ">=") {
return (a >= b);
}
if (opr_is == "smaller_equal_to" || opr_is == "<=") {
return (a <= b);
}
if (opr_is == "not_equal_to" || opr_is == "!=") {
return (a != b);
}
if (opr_is == "square_of" || opr_is == "#=") {
return (b * b == a);
}
throw runtime_error("No the opr_is!");
}
bool pd_is(double a, double b, string opr_is) {
if (opr_is == "bigger_than" || opr_is == ">") {
return (a > b);
}
if (opr_is == "smaller_than" || opr_is == "<") {
return (a < b);
}
if (opr_is == "equal_to" || opr_is == "==") {
return (a == b);
}
if (opr_is == "bigger_equal_to" || opr_is == ">=") {
return (a >= b);
}
if (opr_is == "smaller_equal_to" || opr_is == "<=") {
return (a <= b);
}
if (opr_is == "not_equal_to" || opr_is == "!=") {
return (a != b);
}
if (opr_is == "square_of" || opr_is == "#=") {
return (b * b == a);
}
throw runtime_error("No the opr_is!");
}
bool pd_is(string a, string b, string opr_is) {
if (opr_is == "bigger_than" || opr_is == ">") {
return (a > b);
}
if (opr_is == "smaller_than" || opr_is == "<") {
return (a < b);
}
if (opr_is == "equal_to" || opr_is == "==") {
return (a == b);
}
if (opr_is == "bigger_equal_to" || opr_is == ">=") {
return (a >= b);
}
if (opr_is == "smaller_equal_to" || opr_is == "<=") {
return (a <= b);
}
if (opr_is == "not_equal_to" || opr_is == "!=") {
return (a != b);
}
throw runtime_error("No the opr_is!");
}
int let(string name_a, string name_b, string let_to_opr) {
string tp_a = deftype(name_a), tp_b = deftype(name_b), type;
if (tp_a != tp_b) {
return LET_ERROR;
}
type = tp_a;
if (type == "int") {
if (let_to_opr == "is" || let_to_opr == "=") {
def[name_a].d = def[name_b].d;
} else if (let_to_opr == "plus" || let_to_opr == "+=") {
def[name_a].d += def[name_b].d;
} else if (let_to_opr == "minus" || let_to_opr == "-=") {
def[name_a].d -= def[name_b].d;
} else if (let_to_opr == "times" || let_to_opr == "*=") {
def[name_a].d *= def[name_b].d;
} else if (let_to_opr == "divide" || let_to_opr == "/=") {
def[name_a].d /= def[name_b].d;
} else if (let_to_opr == "mod" || let_to_opr == "%=") {
def[name_a].d %= def[name_b].d;
} else if (let_to_opr == "and" || let_to_opr == "&&=") {
def[name_a].d &= def[name_b].d;
} else if (let_to_opr == "or" || let_to_opr == "||=") {
def[name_a].d |= def[name_b].d;
} else if (let_to_opr == "xor" || let_to_opr == "^^=") {
def[name_a].d ^= def[name_b].d;
} else if (let_to_opr == "nor" || let_to_opr == "!|=") {
def[name_a].d = ~(def[name_a].d | def[name_b].d);
} else if (let_to_opr == "lshift" || let_to_opr == "<<=") {
def[name_a].d <<= def[name_b].d;
} else if (let_to_opr == "rshift" || let_to_opr == ">>=") {
def[name_a].d >>= def[name_b].d;
} else if (let_to_opr == "nxor" || let_to_opr == "!^=") {
def[name_a].d = ~(def[name_a].d ^ def[name_b].d);
} else if (let_to_opr == "nand" || let_to_opr == "!&=") {
def[name_a].d = ~(def[name_a].d ^ def[name_b].d);
} else if (let_to_opr == "pow" || let_to_opr == "^=") {
def[name_a].d = int(pow(def[name_a].d, def[name_b].d));
} else {
return LET_ERROR;
}
} else if (type == "string") {
if (let_to_opr == "is" || let_to_opr == "=") {
def[name_a].s = def[name_b].s;
} else if (let_to_opr == "plus" || let_to_opr == "+=") {
def[name_a].s += def[name_b].s;
} else {
return LET_ERROR;
}
} else if (type == "double") {
if (let_to_opr == "is" || let_to_opr == "=") {
def[name_a].lf = def[name_b].lf;
} else if (let_to_opr == "plus" || let_to_opr == "+=") {
def[name_a].lf += def[name_b].lf;
} else if (let_to_opr == "minus" || let_to_opr == "-=") {
def[name_a].lf -= def[name_b].lf;
} else if (let_to_opr == "times" || let_to_opr == "*=") {
def[name_a].lf *= def[name_b].lf;
} else if (let_to_opr == "divide" || let_to_opr == "/=") {
def[name_a].lf /= def[name_b].lf;
} else if (let_to_opr == "mod" || let_to_opr == "%=") {
def[name_a].d = fmod(def[name_a].lf, def[name_b].lf);
} else if (let_to_opr == "pow" || let_to_opr == "^=") {
def[name_a].d = pow(def[name_a].lf, def[name_b].lf);
} else {
return LET_ERROR;
}
}
return 0;
}
int math() {
string type;
cin >> type;
if (type == "fib") {
string name_fib, name_to;
cin >> name_fib >> name_to;
if (!def.count(name_fib) || (!def.count(name_to) && name_to != "print")) {
retnum = DEF_NOT_DEFINE;
return -1;
}
if (deftype(name_fib) != "int") {
retnum = TYPE_NOT_INT;
return -1;
}
if (name_to == "print") {
set_out;
cout << out << Fib(int_value(name_fib)) << endl;
set_in;
} else {
def[name_to].d = Fib(int_value(name_fib));
}
return 0;
} else if (type == "sin" || type == "cos" || type == "tan"
|| type == "sqrt" || type == "cbrt" || type == "log2"
|| type == "log10") {
string name_math, name_to;
cin >> name_math >> name_to;
if (!def.count(name_math) || (!def.count(name_to) && name_to != "print")) {
retnum = DEF_NOT_DEFINE;
return -1;
}
if (deftype(name_math) != "double") {
retnum = TYPE_NOT_DOUBLE;
return -1;
}
if (name_to == "print") {
set_out;
if (type == "sin") {
cout << out << sin(double_value(name_math)) << endl;
} else if (type == "cos") {
cout << out << cos(double_value(name_math)) << endl;
} else if (type == "tan") {
cout << out << tan(double_value(name_math)) << endl;
} else if (type == "sqrt") {
cout << out << sqrt(double_value(name_math)) << endl;
} else if (type == "cbrt") {
cout << out << cbrt(double_value(name_math)) << endl;
} else if (type == "log2") {
cout << out << log2(double_value(name_math)) << endl;
} else if (type == "log10") {
cout << out << log10(double_value(name_math)) << endl;
}
set_in;
} else {
if (type == "sin") {
def[name_to].lf = sin(double_value(name_math));
} else if (type == "cos") {
def[name_to].lf = cos(double_value(name_math));
} else if (type == "tan") {
def[name_to].lf = tan(double_value(name_math));
} else if (type == "sqrt") {
def[name_to].lf = sqrt(double_value(name_math));
} else if (type == "cbrt") {
def[name_to].lf = cbrt(double_value(name_math));
} else if (type == "log2") {
def[name_to].lf = log2(double_value(name_math));
} else if (type == "log10") {
def[name_to].lf = log10(double_value(name_math));
}
}
return 0;
} else {
retnum = OPR_NOT_TYPE;
return -1;
}
}
int main() {
SetConsoleColor(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);
cout << "-------------[Cnle7.0]---------\n";
for (int line = 1; 1; line++) {
SetConsoleColor(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);
cout << "line(" << line << ") ";
set_in;
cin >> fopr; //input
if (isopr("def")) {
//define num
string def_name, def_type;
bool flag = false;
cin >> def_type;
while (1) {
cin >> def_name;
if (def.count(def_name)) {
retnum = DEF_IS_DEFINED;
flag = true;
break;
}
if (def_type == "int") {
int def_value;
cin >> def_value;
def[def_name] = {def_value, 0, "", "int", "none"};
} else if (def_type == "string") {
string def_value;
cin >> def_value;
def[def_name] = {0, 0, def_value, "string", "none"};
} else if (def_type == "double") {
double def_value;
cin >> def_value;
def[def_name] = {0, def_value, "", "double", "none"};
} else if (def_type == "stack<int>") {
def[def_name] = {0, 0, "", "stack", "int"};
} else if (def_type == "stack<string>") {
def[def_name] = {0, 0, "", "stack", "string"};
} else if (def_type == "stack<double>") {
def[def_name] = {0, 0, "", "stack", "double"};
} else if (def_type == "queue<int>") {
def[def_name] = {0, 0, "", "queue", "int"};
} else if (def_type == "queue<string>") {
def[def_name] = {0, 0, "", "queue", "string"};
} else if (def_type == "queue<double>") {
def[def_name] = {0, 0, "", "queue", "double"};
} else {
retnum = DEF_TYPE_ERROR;
flag = true;
break;
}
string and_;
cin >> and_;
if (and_ == "none" || and_ == ";") {
break;
} else if (and_ != "and" && and_ != ",") {
retnum = UNKNOW_ERROR;
flag = true;
break;
}
}
if (flag) {
break;
}
} else if (isopr("print")) {
set_out;
cout << out << " ";
set_in;
bool flag = false;
while (1) {
string print_num_type;
cin >> print_num_type;
if (print_num_type == ":def") {
string def_print_name;
cin >> def_print_name;
if (!def.count(def_print_name)) {
retnum = DEF_NOT_DEFINE;
flag = true;
break;
} else if (deftype(def_print_name) == "int") {
set_out;
cout << int_value(def_print_name) << " ";
set_in;
//end
} else if (deftype(def_print_name) == "string") {
set_out;
cout << str_value(def_print_name) << " ";
set_in;
//end
} else if (deftype(def_print_name) == "double") {
set_out;
cout << double_value(def_print_name) << " ";
set_in;
//end
} else {
retnum = PRINT_TYPE_ERROR;
flag = true;
break;
}
} else if (print_num_type == ":str") {
string put_string;
cin >> put_string;
set_out;
cout << put_string << " ";
set_in;
} else if (print_num_type == ":is") {
string is_typename;
cin >> is_typename;
if (is_typename == "value") {
string is_type_a, is_type_b, is_type_opr;
cin >> is_type_a >> is_type_opr >> is_type_b;
if (!def.count(is_type_a) || !def.count(is_type_b)) {
retnum = DEF_NOT_DEFINE;
flag = true;
break;
}
if (deftype(is_type_a) == "int" && deftype(is_type_a) == "int") {
set_out;
cout << btstr(pd_is(int_value(is_type_a), int_value(is_type_b), is_type_opr)) << " ";
set_in
} else if (deftype(is_type_a) == "string" && deftype(is_type_a) == "string") {
set_out;
cout << btstr(pd_is(str_value(is_type_a), str_value(is_type_b), is_type_opr)) << " ";
set_in;
} else if (deftype(is_type_a) == "double" && deftype(is_type_a) == "double") {
set_out;
cout << btstr(pd_is(double_value(is_type_a), double_value(is_type_b), is_type_opr)) << " ";
set_in;
} else {
retnum = UNKNOW_ERROR;
flag = true;
break;
}
} else if (is_typename == "number") {
string is_type;
cin >> is_type;
if (is_type == "int") {
int number_a, number_b;
string number_opr;
cin >> number_a >> number_opr >> number_b;
set_out;
cout << btstr(pd_is(number_a, number_b, number_opr)) << " ";
set_in;
} else if (is_type == "string") {
string number_a, number_b;
string number_opr;
cin >> number_a >> number_opr >> number_b;
set_out;
cout << btstr(pd_is(number_a, number_b, number_opr)) << " ";
set_in;
} else if (is_type == "double") {
double number_a, number_b;
string number_opr;
cin >> number_a >> number_opr >> number_b;
set_out;
cout << btstr(pd_is(number_a, number_b, number_opr)) << " ";
set_in;
} else {
retnum = PRINT_TYPE_ERROR;
flag = true;
break;
}
}
} else {
retnum = PRINT_TYPE_ERROR;
break;
}
string __and;
cin >> __and;
if (__and == "none" || __and == ";") {
break;
} else if (__and != "and" && __and != ",") {
retnum = PRINT_TYPE_ERROR;
flag = true;
break;
}
}
cout << endl;
if (flag) {
break;
}
} else if (isopr("file_in")) {
std::string inf_name,kfile_name;
cin >> kfile_name >> inf_name;
std::ifstream file(kfile_name);
if (deftype(inf_name) == "int") {
file>>def[inf_name].d;
} else if (deftype(inf_name) == "double") {
file>>def[inf_name].lf;
} else if (deftype(inf_name) == "string") {
file>>def[inf_name].s;
} else {
string in_type;
file>>in_type;
def[inf_name].type = in_type;
if (in_type == "int") {
file>>def[inf_name].d;
} else if (in_type == "double") {
file>>def[inf_name].lf;
} else if (in_type == "string") {
file>>def[inf_name].s;
} else {
file.close();
retnum = FILE_ERROR;
break;
}
}
file.close();
} else if (isopr("file_out")) {
std::string inf_name, kfile_name;
cin >> kfile_name >> inf_name;
FILE* file = fopen(kfile_name.c_str(), "w");
fprintf(file,"%s",inf_name.c_str());
fclose(file);
} else if (isopr("no_line") || isopr("//")) {
string no__line;
cin >> no__line;
} else if (isopr("let")) {
string let_a, let_b, let_opr;
int __isret;
cin >> let_a >> let_opr >> let_b;
if (deftype(let_a) == "string" && deftype(let_b) == "int") {
if (let_opr == "times" || let_opr == "*=") {
def[let_a].s *= int_value(let_b);
} else if (let_opr == "divide" || let_opr == "/=") {
def[let_a].s /= int_value(let_b);
} else {
retnum = LET_ERROR;
break;
}
} else {
__isret = let(let_a, let_b, let_opr);
if (__isret) {
retnum = __isret;
break;
}
}
} else if (isopr("stack")) {
string name, stack_do;
cin >> name >> stack_do;
if (!def.count(name)) {
retnum = DEF_NOT_DEFINE;
break;
}
if (stack_do == "push") {
if (def[name].type_sq == "int") {
int push_v;
cin >> push_v;
si_def[name].push(push_v);
} else if (def[name].type_sq == "string") {
string push_v;
cin >> push_v;
ss_def[name].push(push_v);
} else if (def[name].type_sq == "double") {
double push_v;
cin >> push_v;
sd_def[name].push(push_v);
} else {
retnum = STACK_ERROR;
break;
}
} else if (stack_do == "pop") {
if (def[name].type_sq == "int") {
si_def[name].pop();
} else if (def[name].type_sq == "string") {
ss_def[name].pop();
} else if (def[name].type_sq == "double") {
sd_def[name].pop();
} else {
retnum = STACK_ERROR;
break;
}
} else if (stack_do == "top") {
if (def[name].type_sq == "int") {
set_out;
cout << out << si_def[name].top() << endl;
set_in;
} else if (def[name].type_sq == "string") {
set_out;
cout << out << ss_def[name].top() << endl;
set_in;
} else if (def[name].type_sq == "double") {
set_out;
cout << out << sd_def[name].top() << endl;
set_in;
} else {
retnum = STACK_ERROR;
break;
}
} else {
retnum = STACK_ERROR;
break;
}
} else if (isopr("queue")) {
string name, queue_do;
cin >> name >> queue_do;
if (!qd_def.count(name) && !qi_def.count(name) && !qs_def.count(name)) {
retnum = DEF_NOT_DEFINE;
break;
}
if (queue_do == "push") {
if (def[name].type_sq == "int") {
int push_v;
cin >> push_v;
qi_def[name].push(push_v);
} else if (def[name].type_sq == "string") {
string push_v;
cin >> push_v;
qs_def[name].push(push_v);
} else if (def[name].type_sq == "double") {
double push_v;
cin >> push_v;
qd_def[name].push(push_v);
} else {
retnum = QUEUE_ERROR;
break;
}
} else if (queue_do == "pop") {
if (def[name].type_sq == "int") {
qi_def[name].pop();
} else if (def[name].type_sq == "string") {
qs_def[name].pop();
} else if (def[name].type_sq == "double") {
qd_def[name].pop();
} else {
retnum = QUEUE_ERROR;
break;
}
} else if (queue_do == "front") {
if (def[name].type_sq == "int") {
set_out;
cout << out << qi_def[name].front() << endl;
set_in;
} else if (def[name].type_sq == "string") {
set_out;
cout << out << qs_def[name].front() << endl;
set_in;
} else if (def[name].type_sq == "double") {
set_out;
cout << out << qd_def[name].front() << endl;
set_in;
} else {
retnum = QUEUE_ERROR;
break;
}
} else {
retnum = UNKNOW_ERROR;
break;
}
} else if (isopr("to")) {
string a_type, a_name, dt;
cin >> a_name >> a_type;
if (!def.count(a_name)) {
retnum = DEF_NOT_DEFINE;
break;
}
dt = deftype(a_name);
if (a_type == deftype(a_name)) continue;
if (dt == "string") {
if (a_type == "int") {
int those_num = 0;
bool is_n = 1, is_err = false;
string thstr = str_value(a_name);
for (int i = 0; i < int(thstr.length()); i++) {
if (thstr[i] == '-' && i == 0) {
is_n = 0;
} else if (thstr[i] == '-') {
is_err = true;
retnum = TO_ERROR;
break;
} else {
those_num = those_num * 10 + thstr[i] - 48;
}
}
if (is_err) {
break;
}
def[a_name].d = (is_n) ? those_num : (-those_num);
def[a_name].s = "";
def[a_name].type = "int";
} else if (a_type == "double") {
double it = 0, those_num = 0, down = 0;
bool is_n = 1, flag = 0, kflag = false;
string thstr = str_value(a_name);
for (int i = 0; i < int(thstr.length()); i++) {
if (thstr[i] == '-' && i == 0) {
is_n = 0;
} else if (thstr[i] == '-') {
kflag = true;
retnum = TO_ERROR;
break;
} else if (thstr[i] == '.') {
if (i == 0 || i == int(thstr.length()) - 1) {
retnum = TO_ERROR;
kflag = true;
break;
} else {
flag = true;
}
} else if (thstr[i] >= '0' && thstr[i] <= '9') {
if (flag) {
down = down * 10.0 + thstr[i] - 48.0;
it++;
} else {
those_num = those_num * 10.0 + thstr[i] - 48.0;
}
} else {
retnum = TO_ERROR;
kflag = true;
break;
}
}
those_num += down / pow(10, it);
def[a_name].lf = (is_n) ? those_num : (-those_num);
if (kflag) {
break;
}
} else {
retnum = TO_ERROR;
break;
}
} else if (dt == "double") {
if (a_type == "int") {
def[a_name].d = floor(int_value(a_name));
def[a_name].lf = 0;
def[a_name].type = "int";
} else if (a_type == "string") {
retnum = TO_ERROR;
break;
}
} else if (dt == "int") {
if (a_type == "double") {
def[a_name].lf = double(int_value(a_name));
def[a_name].d = 0;
def[a_name].type = "double";
} else if (a_type == "string") {
string itstr = "";
int thisint = int_value(a_name);
if (thisint < 0) {
itstr = "-";
} else if (thisint == 0) {
itstr = "0";
} else {
while (thisint) {
itstr += char(thisint % 10 + '0');
thisint /= 10;
}
}
def[a_name].s = itstr;
def[a_name].type = "string";
def[a_name].d = 0;
} else {
retnum = TO_ERROR;
break;
}
} else {
retnum = TO_ERROR;
break;
}
} else if (isopr("type")) {
string name;
cin >> name;
set_out;
cout << out << deftype(name) << endl;
set_in;
} else if (isopr("math")) {
int r = math();
if (r == -1) {
break;
}
} else if (isopr("help")) {
string help_type;
cin >> help_type;
set_out;
if (help_type == "def") {
cout << "def定义 ---+--- 变量类型(int/double/string) --- 变量名name --- 变量值val --- 分隔符(,/and/;/none)\n";
cout << " |\n";
cout << " +--- 变量类型(stack<(int/double/string)>/queue<(int/double/string)>) --- 分隔符(,/and/;/none)\n";
} else if (help_type == "print") {
cout << "print输出 ---+--- 输出变量:def --- 变量名name --- 分隔符(,/and/;/none)\n";
cout << " |\n";
cout << " +--- 输出字符串:str --- 字符串str(val) --- 分隔符(,/and/;/none) \n";
cout << " |\n";
cout << " +--- 输出布尔值:is ---+--- 变量为参数value --- val_a --- (opr) --- val_b --- 分隔符(,/and/;/none) \n";
cout << " |\n";
cout << " +--- 常量为参数number --- type(int/double/string) --- num --- (opr) --- num --- 分隔符(,/and/;/none)\n";
} else if (help_type == "stack") {
cout << "stack栈操作 ---+--- opr(top栈顶/pop弹出) \n";
cout << " | \n";
cout << " +--- opr(push压入) --- 常量val\n";
} else if (help_type == "queue") {
cout << "queue队列操作 ---+--- opr(front队首/pop弹出) \n";
cout << " | \n";
cout << " +--- opr(push压入) --- 常量val\n";
} else if (help_type == "let") {
cout << "let赋值及运算 --- 变量val_a --- 操作符号opr(string) --- 变量valb\n";
} else if (help_type == "no_line") {
cout << "no_line注释 --- 字符串line(string)\n";
} else if (help_type == "math") {
cout << "math数学运算 ---+--- opr(fib) --- val(int) \n";
cout << " | \n";
cout << " +--- opr(sin/cos/tan/sqrt) --- val(double)\n";
} else if (help_type == "file_in") {
cout << "file_in文件输入 --- 文件名fname --- 变量名(已定义)\n";
cout << " |\n";
cout << " +- 变量名(未定义,文件中的第一个字符串为变量类型名)\n";
} else if (help_type == "file_out") {
cout << "file_out文件输出 --- 文件名fname --- 输出的字符串str_k\n";
} else if (help_type == "to") {
cout << "to类型转换(有一些功能未开发) --- 变量名a --- 类型名type\n";
}
set_in;
} else if (isopr("end")) {
cout << endl;
retnum = NONE_ERR;
break;
} else {
retnum = OPR_NOT_TYPE;
break;
}
}
end_cnle(retnum);
return 0;
}