mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-07-26 21:08:45 +08:00
fixed bug
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
int exit_type=0;
|
int exit_type=0;
|
||||||
std::stack<var> ret_stack; // for function ret use
|
std::stack<var> ret_stack; // for function ret use
|
||||||
std::list<var> parameter; // for function call use
|
|
||||||
|
|
||||||
|
|
||||||
var abstract_syntax_tree::calculation()
|
var abstract_syntax_tree::calculation()
|
||||||
@@ -469,10 +468,10 @@ var abstract_syntax_tree::call_identifier()
|
|||||||
}
|
}
|
||||||
else if(i->type==__call_function && temp.get_type()==__var_function)
|
else if(i->type==__call_function && temp.get_type()==__var_function)
|
||||||
{
|
{
|
||||||
parameter.clear();
|
std::list<var> parameter;
|
||||||
for(std::list<abstract_syntax_tree>::iterator j=i->children.begin();j!=i->children.end();++j)
|
for(std::list<abstract_syntax_tree>::iterator j=i->children.begin();j!=i->children.end();++j)
|
||||||
parameter.push_back(j->calculation());
|
parameter.push_back(j->calculation());
|
||||||
temp=temp.get_function().run_func();
|
temp=temp.get_function().run_func(parameter);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -738,7 +737,7 @@ int abstract_syntax_tree::run_ifelse()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
var abstract_syntax_tree::run_func()
|
var abstract_syntax_tree::run_func(std::list<var> parameter)
|
||||||
{
|
{
|
||||||
var ret;
|
var ret;
|
||||||
scope.add_new_block_scope();
|
scope.add_new_block_scope();
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ class abstract_syntax_tree
|
|||||||
void run_root();
|
void run_root();
|
||||||
int run_loop();
|
int run_loop();
|
||||||
int run_ifelse();
|
int run_ifelse();
|
||||||
var run_func();
|
var run_func(std::list<var>);
|
||||||
int run_block();
|
int run_block();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,5 @@ void alert_sound()
|
|||||||
/* global varia in abstract_syntax_tree.cpp :
|
/* global varia in abstract_syntax_tree.cpp :
|
||||||
int exit_type; // record the state of runtime
|
int exit_type; // record the state of runtime
|
||||||
std::stack<var> ret_stack; // for function ret use
|
std::stack<var> ret_stack; // for function ret use
|
||||||
std::list<var> parameter; // for function call use
|
|
||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -88,6 +88,13 @@ class resource_file
|
|||||||
resource.clear();
|
resource.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
void add_lib()
|
||||||
|
{
|
||||||
|
std::string lib_name;
|
||||||
|
lib_name="lib/math.nas";
|
||||||
|
input_file(lib_name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
void input_file(std::string filename)
|
void input_file(std::string filename)
|
||||||
{
|
{
|
||||||
std::ifstream fin(filename,std::ios::binary);
|
std::ifstream fin(filename,std::ios::binary);
|
||||||
|
|||||||
+11
-5
@@ -1,12 +1,18 @@
|
|||||||
var fabs=func(__x)
|
var abs=func(__x)
|
||||||
{
|
{
|
||||||
if(x>0){return __x;}
|
if(__x>0){return __x;}
|
||||||
else{return -__x;}
|
else{return -__x;}
|
||||||
};
|
};
|
||||||
|
|
||||||
var ln=func(__x)
|
var asr=func(__x,__y)
|
||||||
{
|
{
|
||||||
return (1+8/(1+__x)+1/__x)*(__x-1)/6;
|
if(abs(__y-__x)<=0.1){return (1/__x+8/(__x+__y)+1/__y)*(__y-__x)/6;}
|
||||||
|
var __mid=(__x+__y)/2;
|
||||||
|
return asr(__x,__mid)+asr(__mid,__y);
|
||||||
|
};
|
||||||
|
var ln=func(_x)
|
||||||
|
{
|
||||||
|
return asr(1,_x);
|
||||||
};
|
};
|
||||||
|
|
||||||
var log=func(__a,__x)
|
var log=func(__a,__x)
|
||||||
@@ -26,7 +32,7 @@ var pow=func(__x,__num)
|
|||||||
{
|
{
|
||||||
if(__num==0){return 1;}
|
if(__num==0){return 1;}
|
||||||
else if(__num<0){return 1/pow(__x,-__num);}
|
else if(__num<0){return 1/pow(__x,-__num);}
|
||||||
else{return exp(__x*ln(__num));}
|
else{return exp(__num*ln(__x));}
|
||||||
};
|
};
|
||||||
|
|
||||||
var sigmoid=func(__x)
|
var sigmoid=func(__x)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ int main()
|
|||||||
std::cout<<">> 7. [del ] |delete program in memory."<<std::endl;
|
std::cout<<">> 7. [del ] |delete program in memory."<<std::endl;
|
||||||
std::cout<<">> 8. [run ] |run the programme in stack. (-lexer -parser)"<<std::endl;
|
std::cout<<">> 8. [run ] |run the programme in stack. (-lexer -parser)"<<std::endl;
|
||||||
std::cout<<">> 9. [rs ] |check the source program."<<std::endl;
|
std::cout<<">> 9. [rs ] |check the source program."<<std::endl;
|
||||||
|
std::cout<<">>10. [lib ] |add lib into resource codes."<<std::endl;
|
||||||
}
|
}
|
||||||
else if(command=="cls")
|
else if(command=="cls")
|
||||||
{
|
{
|
||||||
@@ -42,6 +43,8 @@ int main()
|
|||||||
lex.scanner(prog.get_resource());
|
lex.scanner(prog.get_resource());
|
||||||
lex.print_token_list();
|
lex.print_token_list();
|
||||||
}
|
}
|
||||||
|
else if(command=="lib")
|
||||||
|
prog.add_lib();
|
||||||
else if(command=="del")
|
else if(command=="del")
|
||||||
{
|
{
|
||||||
prog.set_clear();
|
prog.set_clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user