#include <iostream>
#include <map>
#include <string>
#include <iomanip>
using namespace std;
struct nodef{
int d;
string s;
string type;
};
map<string,nodef> def;
int retnum;
string fopr;//the first operator
const string out="<<< ",in=">>> ";
bool pd_is(int a,int b,string opr_is){
if(opr_is=="bigger_than"){
return (a>b);
}
if(opr_is=="smaller_than"){
return (a<b);
}
if(opr_is=="equal_to"){
return (a==b);
}
if(opr_is=="bigger_equal_to"){
return (a>=b);
}
if(opr_is=="smaller_equal_to"){
return (a<=b);
}
if(opr_is=="not_equal_to"){
return (a!=b);
}
if(opr_is=="square_of"){
return (b*b==a);
}
}
bool pd_is(string a,string b,string opr_is){
if(opr_is=="bigger_than"){
return (a>b);
}
if(opr_is=="smaller_than"){
return (a<b);
}
if(opr_is=="equal_to"){
return (a==b);
}
if(opr_is=="bigger_equal_to"){
return (a>=b);
}
if(opr_is=="smaller_equal_to"){
return (a<=b);
}
if(opr_is=="not_equal_to"){
return (a!=b);
}
}
string btstr(bool in__bo){
return (in__bo)?"True":"False";
}
int int_value(string name){
return def[name].d;
}
string str_value(string name){
return def[name].s;
}
string deftype(string name){
return def[name].type;
}
bool isopr(string __in){
return (__in==fopr);
}
int main(){
cout<<"---------Cnle1.0正式版---------\n";
for(int line=1;1;line++){
cout<<"line"<<setw(5)<<line<<":\t";
cin>>fopr;//input
if(isopr("def")){
//define num
string def_name,def_type;
cin>>def_type;
while(1){
cin>>def_name;
if(def_type=="int"){
int def_value;
cin>>def_value;
def[def_name]={def_value,"","int"};
}else if(def_type=="string"){
string def_value;
cin>>def_value;
def[def_name]={0,def_value,"string"};
}else{
retnum=1;
break;
}
string and_;
cin>>and_;
if(and_=="none"){
break;
}
}
//end
//def int a (value,::int) and/none
//def string a (value::string) and/none
}else if(isopr("print")){
cout<<out<<" ";
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=3;
break;
}else if(deftype(def_print_name)=="int"){
cout<<int_value(def_print_name)<<" ";
//end
}else if(deftype(def_print_name)=="string"){
cout<<str_value(def_print_name)<<" ";
//end
}
}else if(print_num_type==":str"){
string put_string;
cin>>put_string;
cout<<put_string;
}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=3;
break;
}if(deftype(is_type_a)=="int" && deftype(is_type_a)=="int"){
cout<<btstr(pd_is(int_value(is_type_a),int_value(is_type_b),is_type_opr))<<" ";
}else if(deftype(is_type_a)=="string" && deftype(is_type_a)=="string"){
cout<<btstr(pd_is(str_value(is_type_a),str_value(is_type_b),is_type_opr))<<" ";
}else{
retnum=4;
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;
cout<<btstr(pd_is(number_a,number_b,number_opr))<<" ";
}else if(is_type=="string"){
string number_a,number_b;
string number_opr;
cin>>number_a>>number_opr>>number_b;
cout<<btstr(pd_is(number_a,number_b,number_opr))<<" ";
}
}
}else{
retnum=2;
break;
}
string __and;
cin>>__and;
if(__and=="none"){
break;
}
}
cout<<endl;
}else if(isopr("no_line")){
string no__line;
cin>>no__line;
}else if(isopr("end::main")){
break;
}
}
cout<<"--------------------------------\n";
if(retnum==0){
cout<<"This program is return.No error.\n"<<"Put the keyboard to continue. . .";
}else if(retnum==1){
cout<<"This program is return."<<"[error]the def_opr was not the type.\n"<<"Put the keyboard to continue. . .";
}else if(retnum==2){
cout<<"This program is return."<<"[error]the print_opr was not the type.\n"<<"Put the keyboard to continue. . .";
}else if(retnum==3){
cout<<"This program is return."<<"[error]the def was not define!\n"<<"Put the keyboard to continue. . .";
}else if(retnum==4){
cout<<"This program is return."<<"[error]the print_num_value type was diffrent!\n"<<"Put the keyboard to continue. . .";
}else{
cout<<"None [error]!!!";
}
return 0;
}剪贴板
剪贴板 tl9us1ue
剪贴板信息
剪贴板信息
- 收录
- 更新