diff --git a/balloon/abstract_syntax_tree.cpp b/balloon/abstract_syntax_tree.cpp index f0ffea6..56bbb3a 100644 --- a/balloon/abstract_syntax_tree.cpp +++ b/balloon/abstract_syntax_tree.cpp @@ -478,11 +478,20 @@ var abstract_syntax_tree::call_identifier() { var place=i->children.front().calculation(); if(place.get_type()==__var_number) - temp=temp.get_array_member((int)place.get_number()); + { + if(place.get_number()>=0) + temp=temp.get_array_member((int)place.get_number()); + else + { + exit_type=__get_value_failure; + std::cout<<">>[Runtime-error] line"<line<<": number shouldn't be less than 0 when calling an array."<>[Runtime-error] line "<>[Runtime-error] line "<line<<": "; print_detail_token(i->type); std::cout<<": incorrect type \'"; print_scalar(temp.get_type()); @@ -496,7 +505,7 @@ var abstract_syntax_tree::call_identifier() if(temp.get_type()==__null_type) { exit_type=__get_value_failure; - std::cout<<">>[Runtime-error] line "<name<<"\' or this value is set to __null_type. detail: "; + std::cout<<">>[Runtime-error] line "<line<<": cannot find a hash-member named \'"<name<<"\' or this value is set to __null_type. detail: "; temp.print_var(); std::cout<<"."<>[Runtime-error] line "<>[Runtime-error] line "<line<<": "; print_detail_token(i->type); std::cout<<": incorrect type \'"; print_scalar(temp.get_type()); @@ -555,11 +564,20 @@ var* abstract_syntax_tree::get_var_addr() { var place=i->children.front().calculation(); if(place.get_type()==__var_number) - addr=addr->get_array_member_addr((int)place.get_number()); + { + if(place.get_number()>=0) + addr=addr->get_array_member_addr((int)place.get_number()); + else + { + exit_type=__get_value_failure; + std::cout<<">>[Runtime-error] line"<line<<": number shouldn't be less than 0 when calling an array."<>[Runtime-error] line "<>[Runtime-error] line "<line<<": "; print_detail_token(i->type); std::cout<<": incorrect type \'"; print_scalar(addr->get_type()); @@ -573,20 +591,20 @@ var* abstract_syntax_tree::get_var_addr() if(addr->get_type()==__null_type) { exit_type=__get_value_failure; - std::cout<<">>[Runtime-error] line "<name<<"\'."<>[Runtime-error] line "<line<<": cannot find a hash-member named \'"<name<<"\'."<type==__call_function && addr->get_type()==__var_function) { exit_type=__error_value_type; - std::cout<<">>[Runtime-error] line "<>[Runtime-error] line "<line<<": function-returned value cannot be assigned."<>[Runtime-error] line "<>[Runtime-error] line "<line<<": "; print_detail_token(i->type); std::cout<<": incorrect type \'"; print_scalar(addr->get_type()); diff --git a/balloon/balloon_lexer.h b/balloon/balloon_lexer.h index a2556cb..d286a2f 100644 --- a/balloon/balloon_lexer.h +++ b/balloon/balloon_lexer.h @@ -5,16 +5,16 @@ reserve words are those below and they are also the reserve words of nasal */ -std::string reserve_word[15]= +std::string reserve_word[14]= { "for","foreach","forindex","while", "var","func","break","continue","return", - "if","else","elsif","nil","and","or" + "if","else","elsif","and","or" }; int is_reserve_word(std::string str) { - for(int i=0;i<15;++i) + for(int i=0;i<14;++i) if(reserve_word[i]==str) return __reserve_word; return __token_identifier; @@ -111,6 +111,11 @@ class resource_file std::cout<<">>[Resource] lack lib file: lib/io.nas ."<>[Resource] lack lib file: lib/basics.nas ."<