Fixed ArrayCopy and ArrayFill functions when handling numbers and strings
This commit is contained in:
@@ -167,354 +167,7 @@ bool rc_preprocessor()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Array_Macros(int tmp_start_token)
|
||||
{
|
||||
//returning true is just saying there were no syntax errors found
|
||||
if(tmp_token[tmp_start_token].length() < 5)
|
||||
return true;
|
||||
if(StringToLower(tmp_token[tmp_start_token].substr(4)).compare("arraydim")!=0 && StringToLower(tmp_token[tmp_start_token].substr(4)).compare("arraysize")!=0 &&
|
||||
StringToLower(tmp_token[tmp_start_token].substr(4)).compare("arraycopy")!=0 && StringToLower(tmp_token[tmp_start_token].substr(4)).compare("arrayfill")!=0)
|
||||
return true;
|
||||
|
||||
int64_t arr_id = 0;
|
||||
vector<string> tmp_macro_token;
|
||||
vector<string> tmp_current_token;
|
||||
//int ArrayDim_id = getIDInScope_ByIndex("ArrayDim");
|
||||
for(int i = tmp_start_token; i < tmp_token.size(); i++)
|
||||
{
|
||||
if(tmp_token[i].substr(0,4).compare("<id>")==0)
|
||||
{
|
||||
if(StringToLower(tmp_token[i].substr(4)).compare("arraydim")==0)
|
||||
{
|
||||
if(tmp_token[i+1].compare("<par>")!=0)
|
||||
{
|
||||
rc_setError("Invalid use of ArrayDim");
|
||||
return false;
|
||||
}
|
||||
if(tmp_token[i+2].substr(0,4).compare("<id>")==0)
|
||||
{
|
||||
arr_id = getIDInScope_ByIndex(tmp_token[i+2].substr(4));
|
||||
if(arr_id < 0)
|
||||
{
|
||||
rc_setError("Identifier must be declared before call to ArrayDim");
|
||||
return false;
|
||||
}
|
||||
|
||||
id[arr_id].isArrayArg = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
rc_setError("Expected Identifier in ArrayDim");
|
||||
return false;
|
||||
}
|
||||
|
||||
int end_token = i+2;
|
||||
int expr_scope = 1;
|
||||
for(end_token; end_token < tmp_token.size(); end_token++)
|
||||
{
|
||||
if(tmp_token[end_token].compare("<par>")==0 || tmp_token[end_token].compare("<square>")==0)
|
||||
expr_scope++;
|
||||
else if(tmp_token[end_token].compare("</par>")==0 || tmp_token[end_token].compare("</square>")==0)
|
||||
expr_scope--;
|
||||
|
||||
if(expr_scope==0 && tmp_token[end_token].compare("</par>")==0)
|
||||
break;
|
||||
}
|
||||
|
||||
tmp_macro_token.clear();
|
||||
for(int n = i; n <= end_token; n++)
|
||||
tmp_macro_token.push_back(tmp_token[n]);
|
||||
|
||||
//cout << "<---- DEBUG ---->" << i << endl;
|
||||
//for(int n = 0; n < token.size(); n++)
|
||||
// cout <<"token[" << n << "] = " << token[n] << endl;
|
||||
|
||||
tmp_current_token.clear();
|
||||
for(int n = 0; n < token.size(); n++)
|
||||
tmp_current_token.push_back(token[n]);
|
||||
|
||||
token.clear();
|
||||
for(int n = 0; n < tmp_macro_token.size(); n++)
|
||||
token.push_back(tmp_macro_token[n]);
|
||||
|
||||
//for(int n = 0; n < token.size(); n++)
|
||||
// cout <<"new token[" << n << "] = " << token[n] << endl;
|
||||
|
||||
|
||||
if(!eval_expression())
|
||||
{
|
||||
rc_setError("Could not evaluate ArrayDim");
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int n = i; n <= end_token; n++)
|
||||
tmp_token[n] = token[n-i];
|
||||
|
||||
token.clear();
|
||||
for(int n = 0; n < tmp_current_token.size(); n++)
|
||||
token.push_back(tmp_current_token[n]);
|
||||
|
||||
//for(int n = 0; n < token.size(); n++)
|
||||
// cout <<"final token[" << n << "] = " << token[n] << endl;
|
||||
return true;
|
||||
|
||||
}
|
||||
else if(StringToLower(tmp_token[i].substr(4)).compare("arraysize")==0)
|
||||
{
|
||||
if(tmp_token[i+1].compare("<par>")!=0)
|
||||
{
|
||||
rc_setError("Invalid use of ArraySize");
|
||||
return false;
|
||||
}
|
||||
if(tmp_token[i+2].substr(0,4).compare("<id>")==0)
|
||||
{
|
||||
arr_id = getIDInScope_ByIndex(tmp_token[i+2].substr(4));
|
||||
if(arr_id < 0)
|
||||
{
|
||||
rc_setError("Identifier must be declared before call to ArraySize");
|
||||
return false;
|
||||
}
|
||||
|
||||
id[arr_id].isArrayArg = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
rc_setError("Expected Identifier in ArraySize");
|
||||
return false;
|
||||
}
|
||||
|
||||
int end_token = i+2;
|
||||
int expr_scope = 1;
|
||||
for(end_token; end_token < tmp_token.size(); end_token++)
|
||||
{
|
||||
if(tmp_token[end_token].compare("<par>")==0 || tmp_token[end_token].compare("<square>")==0)
|
||||
expr_scope++;
|
||||
else if(tmp_token[end_token].compare("</par>")==0 || tmp_token[end_token].compare("</square>")==0)
|
||||
expr_scope--;
|
||||
|
||||
if(expr_scope==0 && tmp_token[end_token].compare("</par>")==0)
|
||||
break;
|
||||
}
|
||||
|
||||
tmp_macro_token.clear();
|
||||
for(int n = i; n <= end_token; n++)
|
||||
tmp_macro_token.push_back(tmp_token[n]);
|
||||
|
||||
|
||||
tmp_current_token.clear();
|
||||
for(int n = 0; n < token.size(); n++)
|
||||
tmp_current_token.push_back(token[n]);
|
||||
|
||||
token.clear();
|
||||
for(int n = 0; n < tmp_macro_token.size(); n++)
|
||||
token.push_back(tmp_macro_token[n]);
|
||||
|
||||
if(!eval_expression(0, token.size()-1, true))//i, end_token))
|
||||
{
|
||||
rc_setError("Could not evaluate ArraySize expression");
|
||||
//for(int n = 0; n < token.size(); n++)
|
||||
// cout << "token["<< n << "] = " << token[n] << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int n = i; n <= end_token; n++)
|
||||
tmp_token[n] = token[n-i];
|
||||
|
||||
token.clear();
|
||||
for(int n = 0; n < tmp_current_token.size(); n++)
|
||||
token.push_back(tmp_current_token[n]);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if(StringToLower(tmp_token[i].substr(4)).compare("arraycopy")==0)
|
||||
{
|
||||
if(tmp_token.size() < 5)
|
||||
{
|
||||
rc_setError("Ivalid use of ArrayCopy");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(tmp_token[i+1].compare("<par>")!=0)
|
||||
{
|
||||
rc_setError("Invalid use of ArrayCopy");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(tmp_token[i+2].substr(0,4).compare("<id>")==0)
|
||||
{
|
||||
arr_id = getIDInScope_ByIndex(tmp_token[i+2].substr(4));
|
||||
if(arr_id < 0)
|
||||
{
|
||||
rc_setError("Identifier must be declared before call to ArrayCopy");
|
||||
return false;
|
||||
}
|
||||
|
||||
id[arr_id].isArrayArg = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
rc_setError("Expected Identifier in ArrayCopy");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!tmp_token[i+3].substr(0,7).compare("<comma>")==0)
|
||||
{
|
||||
rc_setError("Expected comma in ArrayCopy");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(tmp_token[i+4].substr(0,4).compare("<id>")==0)
|
||||
{
|
||||
arr_id = getIDInScope_ByIndex(tmp_token[i+4].substr(4));
|
||||
if(arr_id < 0)
|
||||
{
|
||||
rc_setError("Identifier must be declared before call to ArrayCopy");
|
||||
return false;
|
||||
}
|
||||
|
||||
id[arr_id].isArrayArg = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
rc_setError("Expected Identifier in ArrayCopy");
|
||||
return false;
|
||||
}
|
||||
|
||||
int end_token = i+4;
|
||||
int expr_scope = 1;
|
||||
for(end_token; end_token < tmp_token.size(); end_token++)
|
||||
{
|
||||
if(tmp_token[end_token].compare("<par>")==0 || tmp_token[end_token].compare("<square>")==0)
|
||||
expr_scope++;
|
||||
else if(tmp_token[end_token].compare("</par>")==0 || tmp_token[end_token].compare("</square>")==0)
|
||||
expr_scope--;
|
||||
|
||||
if(expr_scope==0 && tmp_token[end_token].compare("</par>")==0)
|
||||
break;
|
||||
}
|
||||
|
||||
tmp_macro_token.clear();
|
||||
for(int n = i; n <= end_token; n++)
|
||||
tmp_macro_token.push_back(tmp_token[n]);
|
||||
|
||||
//cout << "<---- DEBUG ---->" << i << endl;
|
||||
//for(int n = 0; n < token.size(); n++)
|
||||
// cout <<"token[" << n << "] = " << token[n] << endl;
|
||||
|
||||
tmp_current_token.clear();
|
||||
for(int n = 0; n < token.size(); n++)
|
||||
tmp_current_token.push_back(token[n]);
|
||||
|
||||
token.clear();
|
||||
for(int n = 0; n < tmp_macro_token.size(); n++)
|
||||
token.push_back(tmp_macro_token[n]);
|
||||
|
||||
//for(int n = 0; n < token.size(); n++)
|
||||
// cout <<"new token[" << n << "] = " << token[n] << endl;
|
||||
|
||||
|
||||
if(!eval_expression())
|
||||
{
|
||||
rc_setError("Could not evaluate ArrayCopy");
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int n = i; n <= end_token; n++)
|
||||
tmp_token[n] = token[n-i];
|
||||
|
||||
token.clear();
|
||||
for(int n = 0; n < tmp_current_token.size(); n++)
|
||||
token.push_back(tmp_current_token[n]);
|
||||
|
||||
//for(int n = 0; n < token.size(); n++)
|
||||
// cout <<"final token[" << n << "] = " << token[n] << endl;
|
||||
return true;
|
||||
|
||||
}
|
||||
else if(StringToLower(tmp_token[i].substr(4)).compare("arrayfill")==0)
|
||||
{
|
||||
if(tmp_token[i+1].compare("<par>")!=0)
|
||||
{
|
||||
rc_setError("Invalid use of ArrayFill");
|
||||
return false;
|
||||
}
|
||||
if(tmp_token[i+2].substr(0,4).compare("<id>")==0)
|
||||
{
|
||||
arr_id = getIDInScope_ByIndex(tmp_token[i+2].substr(4));
|
||||
if(arr_id < 0)
|
||||
{
|
||||
rc_setError("Identifier must be declared before call to ArrayFill");
|
||||
return false;
|
||||
}
|
||||
|
||||
id[arr_id].isArrayArg = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
rc_setError("Expected Identifier in ArrayFill");
|
||||
return false;
|
||||
}
|
||||
|
||||
int end_token = i+2;
|
||||
int expr_scope = 1;
|
||||
for(end_token; end_token < tmp_token.size(); end_token++)
|
||||
{
|
||||
if(tmp_token[end_token].compare("<par>")==0 || tmp_token[end_token].compare("<square>")==0)
|
||||
expr_scope++;
|
||||
else if(tmp_token[end_token].compare("</par>")==0 || tmp_token[end_token].compare("</square>")==0)
|
||||
expr_scope--;
|
||||
|
||||
if(expr_scope==0 && tmp_token[end_token].compare("</par>")==0)
|
||||
break;
|
||||
}
|
||||
|
||||
tmp_macro_token.clear();
|
||||
for(int n = i; n <= end_token; n++)
|
||||
tmp_macro_token.push_back(tmp_token[n]);
|
||||
|
||||
//cout << "<---- DEBUG ---->" << i << endl;
|
||||
//for(int n = 0; n < token.size(); n++)
|
||||
// cout <<"token[" << n << "] = " << token[n] << endl;
|
||||
|
||||
tmp_current_token.clear();
|
||||
for(int n = 0; n < token.size(); n++)
|
||||
tmp_current_token.push_back(token[n]);
|
||||
|
||||
token.clear();
|
||||
for(int n = 0; n < tmp_macro_token.size(); n++)
|
||||
token.push_back(tmp_macro_token[n]);
|
||||
|
||||
//for(int n = 0; n < token.size(); n++)
|
||||
// cout <<"new token[" << n << "] = " << token[n] << endl;
|
||||
|
||||
|
||||
if(!eval_expression())
|
||||
{
|
||||
rc_setError("Could not evaluate ArrayFill");
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int n = i; n <= end_token; n++)
|
||||
tmp_token[n] = token[n-i];
|
||||
|
||||
token.clear();
|
||||
for(int n = 0; n < tmp_current_token.size(); n++)
|
||||
token.push_back(tmp_current_token[n]);
|
||||
|
||||
//for(int n = 0; n < token.size(); n++)
|
||||
// cout <<"final token[" << n << "] = " << token[n] << endl;
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool rc_eval(string line)
|
||||
{
|
||||
|
||||
@@ -38,6 +38,7 @@ struct type_error_exception
|
||||
string error_log;
|
||||
string tk_reg;
|
||||
string resolve_reg;
|
||||
int num_args;
|
||||
};
|
||||
|
||||
vector<type_error_exception> byref_type_exception; //This will store the error that might be generated if a user type var is in an expression without its dimensions expressed
|
||||
@@ -1133,7 +1134,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
|
||||
}
|
||||
else if( (id[expr_id].type == ID_TYPE_BYREF_NUM || id[expr_id].type == ID_TYPE_BYREF_STR) && pp_flags == PP_FLAG_ARRAY)
|
||||
{
|
||||
cout << "found array: " << id[expr_id].name << endl << endl;
|
||||
//cout << "found array: " << id[expr_id].name << endl << endl;
|
||||
int s_scope = 0;
|
||||
int arr_token_start = i;
|
||||
int arr_token_end = i;
|
||||
@@ -1425,7 +1426,10 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
|
||||
else if(!type_delete_flag)
|
||||
{
|
||||
if(arg_count != 0)
|
||||
{
|
||||
rc_setError("[0]Expected " + rc_intToString(id[tmp_id].num_args) + " dimension in " + id[tmp_id].name);
|
||||
return false;
|
||||
}
|
||||
|
||||
//cout << "ID_TYPE = " << id[tmp_id].type << ", " << arg_count << ", " << (has_child ? "true" : "false") << endl;
|
||||
|
||||
@@ -1675,7 +1679,8 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
|
||||
type_error_exception tx;
|
||||
tx.error_log = "[0]Expected " + rc_intToString(id[tmp_id].num_args) + " dimension in " + id[tmp_id].name;
|
||||
tx.tk_reg = token[i];
|
||||
//cout << "store = " << tx.tk_reg << endl;
|
||||
tx.num_args = id[tmp_id].num_args;
|
||||
//cout << "store = " << id[tmp_id].name << " = " << tx.tk_reg << " arg_count = " << arg_count << ", expected = " << id[tmp_id].num_args << endl;
|
||||
byref_type_exception.push_back(tx);
|
||||
byref_type_flag = false;
|
||||
}
|
||||
@@ -2253,6 +2258,8 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
|
||||
expr_id = -1;
|
||||
}
|
||||
|
||||
//cout << "dbg data: " << expr_id << " arg = " << args[0] << " type = " << tmp_id_type << " name = " << id[expr_id].name << endl;
|
||||
|
||||
if(expr_id < 0)
|
||||
{
|
||||
rc_setError("ArrayFill macro function does not exists for variable type");
|
||||
@@ -5610,8 +5617,13 @@ bool check_rule()
|
||||
}
|
||||
if(expr_result.substr(0,1).compare("n")==0)
|
||||
vm_asm.push_back("print " + expr_result);
|
||||
else
|
||||
vm_asm.push_back("print$ " + expr_result);
|
||||
else if(expr_result.substr(0,1).compare("s")==0)
|
||||
vm_asm.push_back("print$ " + expr_result);
|
||||
else
|
||||
{
|
||||
rc_setError("Invalid expression in PRINT");
|
||||
return false;
|
||||
}
|
||||
start_token = i;
|
||||
}
|
||||
}
|
||||
@@ -5624,8 +5636,13 @@ bool check_rule()
|
||||
}
|
||||
if(expr_result.substr(0,1).compare("n")==0)
|
||||
vm_asm.push_back("print " + expr_result);
|
||||
else
|
||||
vm_asm.push_back("print$ " + expr_result);
|
||||
else if(expr_result.substr(0,1).compare("s")==0)
|
||||
vm_asm.push_back("print$ " + expr_result);
|
||||
else
|
||||
{
|
||||
rc_setError("Invalid expression in PRINT");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(last_token.compare("<semi>")!=0)
|
||||
vm_asm.push_back("println");
|
||||
|
||||
Reference in New Issue
Block a user