This commit is contained in:
Valk Richard Li
2019-11-10 16:14:56 +08:00
committed by GitHub
parent abae85d498
commit d5d7dbbd69
2 changed files with 12 additions and 10 deletions
+11 -9
View File
@@ -78,7 +78,9 @@ class abstract_syntax_tree
} }
void set_var_string(std::string str) void set_var_string(std::string str)
{ {
var_string=str; var_string="";
for(int i=1;i<(int)str.length()-1;++i)
var_string+=str[i];
return; return;
} }
void set_var_number(std::string str) void set_var_number(std::string str)
@@ -92,8 +94,8 @@ class abstract_syntax_tree
{ {
if(str[1]=='x') if(str[1]=='x')
{ {
int num=0; double num=0;
int pw=1; double pw=1;
for(int i=(int)str.length()-1;i>1;--i) for(int i=(int)str.length()-1;i>1;--i)
{ {
if('0'<=str[i] && str[i]<='9') if('0'<=str[i] && str[i]<='9')
@@ -102,20 +104,20 @@ class abstract_syntax_tree
num+=(10+str[i]-'a')*pw; num+=(10+str[i]-'a')*pw;
else if('A'<=str[i] && str[i]<='F') else if('A'<=str[i] && str[i]<='F')
num+=(10+str[i]-'A')*pw; num+=(10+str[i]-'A')*pw;
pw<<=4; pw*=16;
} }
var_number=(double)num; var_number=num;
} }
else else
{ {
int num=0; double num=0;
int pw=1; double pw=1;
for(int i=(int)str.length()-1;i>1;--i) for(int i=(int)str.length()-1;i>1;--i)
{ {
num+=(str[i]-'0')*pw; num+=(str[i]-'0')*pw;
pw<<=3; pw*=8;
} }
var_number=(double)num; var_number=num;
} }
return; return;
} }
+1 -1
View File
@@ -4,7 +4,7 @@ int main()
resource_programme_process prog; resource_programme_process prog;
nasal_lexer lex; nasal_lexer lex;
nasal_parser pas; nasal_parser pas;
nasal_runtime vm; nasal_vm vm;
std::string command; std::string command;
std::cout<<">> Nasal interpreter by ValKmjolnir"<<std::endl; std::cout<<">> Nasal interpreter by ValKmjolnir"<<std::endl;
std::cout<<">> Input [help] to find help."<<std::endl; std::cout<<">> Input [help] to find help."<<std::endl;