Update
This commit is contained in:
parent
80ef21b0b9
commit
b4468c6cc1
|
@ -478,11 +478,20 @@ var abstract_syntax_tree::call_identifier()
|
|||
{
|
||||
var place=i->children.front().calculation();
|
||||
if(place.get_type()==__var_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"<<i->line<<": number shouldn't be less than 0 when calling an array."<<std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
exit_type=__error_value_type;
|
||||
std::cout<<">>[Runtime-error] line "<<line<<": ";
|
||||
std::cout<<">>[Runtime-error] line "<<i->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 "<<line<<": cannot find a hash-member named \'"<<i->name<<"\' or this value is set to __null_type. detail: ";
|
||||
std::cout<<">>[Runtime-error] line "<<i->line<<": cannot find a hash-member named \'"<<i->name<<"\' or this value is set to __null_type. detail: ";
|
||||
temp.print_var();
|
||||
std::cout<<"."<<std::endl;
|
||||
break;
|
||||
|
@ -516,7 +525,7 @@ var abstract_syntax_tree::call_identifier()
|
|||
else
|
||||
{
|
||||
exit_type=__error_value_type;
|
||||
std::cout<<">>[Runtime-error] line "<<line<<": ";
|
||||
std::cout<<">>[Runtime-error] line "<<i->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)
|
||||
{
|
||||
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"<<i->line<<": number shouldn't be less than 0 when calling an array."<<std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
exit_type=__error_value_type;
|
||||
std::cout<<">>[Runtime-error] line "<<line<<": ";
|
||||
std::cout<<">>[Runtime-error] line "<<i->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 "<<line<<": cannot find a hash-member named \'"<<i->name<<"\'."<<std::endl;
|
||||
std::cout<<">>[Runtime-error] line "<<i->line<<": cannot find a hash-member named \'"<<i->name<<"\'."<<std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(i->type==__call_function && addr->get_type()==__var_function)
|
||||
{
|
||||
exit_type=__error_value_type;
|
||||
std::cout<<">>[Runtime-error] line "<<line<<": function-returned value cannot be assigned."<<std::endl;
|
||||
std::cout<<">>[Runtime-error] line "<<i->line<<": function-returned value cannot be assigned."<<std::endl;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
exit_type=__error_value_type;
|
||||
std::cout<<">>[Runtime-error] line "<<line<<": ";
|
||||
std::cout<<">>[Runtime-error] line "<<i->line<<": ";
|
||||
print_detail_token(i->type);
|
||||
std::cout<<": incorrect type \'";
|
||||
print_scalar(addr->get_type());
|
||||
|
|
|
@ -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 ."<<std::endl;
|
||||
else
|
||||
input_lib_file(lib_name);
|
||||
lib_name="lib/basics.nas";
|
||||
if(access("lib/basics.nas",0))
|
||||
std::cout<<">>[Resource] lack lib file: lib/basics.nas ."<<std::endl;
|
||||
else
|
||||
input_lib_file(lib_name);
|
||||
return;
|
||||
}
|
||||
void input_lib_file(std::string filename)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# this file includes functions:
|
||||
# append
|
||||
# subvec
|
||||
var append(vector,elements...)
|
||||
{
|
||||
return __call_special_inline_function(vector,elements);
|
||||
};
|
||||
|
||||
var subvec(vector,begin,length)
|
||||
{
|
||||
var new_vector=[];
|
||||
for(var i=begin;i<begin+length;i+=1)
|
||||
{
|
||||
append(new_vector,vector[i]);
|
||||
}
|
||||
return new_vector;
|
||||
};
|
||||
|
||||
var int(value)
|
||||
{
|
||||
return __call_Cpp_int(value);
|
||||
};
|
|
@ -1,7 +1,14 @@
|
|||
|
||||
# the function print is written by Cpp: std::cout
|
||||
# so the code is fake XD but the definition is of great use
|
||||
# the function input is written by Cpp: std::cin
|
||||
# so the code is fake XD but the definitions are of great use
|
||||
# the definitions are set to avoid redefinition
|
||||
var print=func(args...)
|
||||
{
|
||||
return __call_cpp_ostream_std_cout(args);
|
||||
};
|
||||
|
||||
var input=func()
|
||||
{
|
||||
return __call_cpp_istream_std_cin();
|
||||
};
|
Loading…
Reference in New Issue