forked from xxq250/Nasal-Interpreter
Fixed bugs
This commit is contained in:
@@ -698,7 +698,7 @@ void abstract_syntax_tree::run_root()
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<">>[Runtime-error] line "<<line<<": redeclaration of \'"<<_name<<"\'."<<std::endl;
|
||||
std::cout<<">>[Runtime-error] line "<<i->line<<": redeclaration of \'"<<_name<<"\'."<<std::endl;
|
||||
exit_type=__redeclaration;
|
||||
break;
|
||||
}
|
||||
@@ -717,7 +717,7 @@ void abstract_syntax_tree::run_root()
|
||||
int ret_type=i->run_loop();
|
||||
if(ret_type==__return)
|
||||
{
|
||||
std::cout<<"[Runtime-error] line "<<line<<": incorrect use of break/continue."<<std::endl;
|
||||
std::cout<<"[Runtime-error] line "<<i->line<<": incorrect use of break/continue."<<std::endl;
|
||||
exit_type=__error_command_use;
|
||||
}
|
||||
scope.pop_last_block_scope();
|
||||
@@ -728,7 +728,7 @@ void abstract_syntax_tree::run_root()
|
||||
int ret_type=i->run_ifelse();
|
||||
if(ret_type==__continue || ret_type==__break || ret_type==__return)
|
||||
{
|
||||
std::cout<<"[Runtime-error] line "<<line<<": incorrect use of break/continue."<<std::endl;
|
||||
std::cout<<"[Runtime-error] line "<<i->line<<": incorrect use of break/continue."<<std::endl;
|
||||
exit_type=__error_command_use;
|
||||
}
|
||||
scope.pop_last_block_scope();
|
||||
@@ -991,7 +991,7 @@ int abstract_syntax_tree::run_block()
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<">>[Runtime-error] line "<<line<<": redeclaration of \'"<<_name<<"\'."<<std::endl;
|
||||
std::cout<<">>[Runtime-error] line "<<i->line<<": redeclaration of \'"<<_name<<"\'."<<std::endl;
|
||||
exit_type=__redeclaration;
|
||||
}
|
||||
}
|
||||
@@ -1015,7 +1015,7 @@ int abstract_syntax_tree::run_block()
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"[Runtime-error] line "<<line<<": incorrect use of break/continue."<<std::endl;
|
||||
std::cout<<"[Runtime-error] line "<<i->line<<": incorrect use of break/continue."<<std::endl;
|
||||
exit_type=__error_command_use;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,10 +166,25 @@ class resource_file
|
||||
totalsource.push_back(*i);
|
||||
return totalsource;
|
||||
}
|
||||
void print_file()
|
||||
void print_file(bool withlib)
|
||||
{
|
||||
int line=1;
|
||||
std::cout<<line<<" ";
|
||||
if(withlib)
|
||||
{
|
||||
for(std::list<char>::iterator i=libsource.begin();i!=libsource.end();++i)
|
||||
{
|
||||
if(32<=*i && *i<128 || *i=='\n')
|
||||
std::cout<<*i;
|
||||
else if(*i=='\t')
|
||||
std::cout<<" ";
|
||||
if(*i=='\n')
|
||||
{
|
||||
++line;
|
||||
std::cout<<line<<" ";
|
||||
}
|
||||
}
|
||||
}
|
||||
for(std::list<char>::iterator i=resource.begin();i!=resource.end();++i)
|
||||
{
|
||||
if(32<=*i && *i<128 || *i=='\n')
|
||||
|
||||
@@ -25,7 +25,8 @@ int main()
|
||||
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<<">> 9. [rs ] |check the source program."<<std::endl;
|
||||
std::cout<<">>10. [sound ] |make noise(?)."<<std::endl;
|
||||
std::cout<<">>10. [total ] |check code with lib."<<std::endl;
|
||||
std::cout<<">>11. [sound ] |make noise(?)."<<std::endl;
|
||||
}
|
||||
else if(command=="cls")
|
||||
{
|
||||
@@ -35,9 +36,15 @@ int main()
|
||||
// MacOS system("clear");
|
||||
}
|
||||
else if(command=="rs")
|
||||
prog.print_file();
|
||||
prog.print_file(false);// false means print resource code without lib
|
||||
else if(command=="exit")
|
||||
break;
|
||||
else if(command=="total")
|
||||
{
|
||||
prog.clear_lib_code();// clear lib code
|
||||
prog.add_lib(); // reload lib code to avoid redefinition
|
||||
prog.print_file(true);// true means print resource code with lib
|
||||
}
|
||||
else if(command=="lexer")
|
||||
{
|
||||
prog.clear_lib_code(); // avoid print lib code
|
||||
@@ -92,7 +99,7 @@ int main()
|
||||
}
|
||||
else if(command=="run")
|
||||
{
|
||||
prog.add_lib();
|
||||
prog.add_lib(); // load lib code
|
||||
lex.scanner(prog.get_resource());
|
||||
lex.generate_detail_token();
|
||||
if(!lex.get_error())
|
||||
@@ -114,7 +121,7 @@ int main()
|
||||
}
|
||||
}
|
||||
else if(command=="sound")
|
||||
alert_sound();
|
||||
alert_sound();// check if the sound works
|
||||
else
|
||||
prog.input_file(command);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user