Bug in func& operator= fixed

This commit is contained in:
Valk Richard Li 2019-08-11 17:11:18 +08:00 committed by GitHub
parent d3db5019b5
commit 98dde4b53b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 43 deletions

View File

@ -26,18 +26,13 @@ class func_stack
{
func_stack_unit *temp=head;
func_stack_unit *this_node=NULL;
if(head->next)
while(temp->next)
{
while(temp->next)
{
this_node=temp;
temp=temp->next;
delete this_node;
}
delete temp;
this_node=temp;
temp=temp->next;
delete this_node;
}
else
delete head;
delete temp;
}
void append_function(std::string &function_name,func &temp_func)
{
@ -54,6 +49,7 @@ class func_stack
temp->next=new func_stack_unit;
temp=temp->next;
temp->next=NULL;
temp->func_name=function_name;
temp->func_statement=temp_func;
return;
}
@ -80,7 +76,6 @@ class func_stack
temp=temp->next;
std::cout<<"function: "<<temp->func_name<<std::endl;
}
std::cout<<"function: "<<temp->func_name<<std::endl;
return;
}
void pop_function()

View File

@ -122,27 +122,33 @@ func::~func()
}
func& func::operator=(const func& temp)
{
token_unit *statement_temp=statement_head;
token_unit *statement_temp=statement_head->next;
token_unit *temp_state=temp.statement_head;
parameter *parameter_temp=parameter_head;
parameter *parameter_temp=parameter_head->next;
parameter *temp_param=temp.parameter_head;
token_unit *statement_last=NULL;
parameter *parameter_last=NULL;
while(statement_temp->next)
if(statement_temp)
{
statement_last=statement_temp;
statement_temp=statement_temp->next;
delete statement_last;
while(statement_temp->next)
{
statement_last=statement_temp;
statement_temp=statement_temp->next;
delete statement_last;
}
delete statement_temp;
}
delete statement_temp;
while(parameter_temp->next)
if(parameter_temp)
{
parameter_last=parameter_temp;
parameter_temp=parameter_temp->next;
delete parameter_last;
while(parameter_temp->next)
{
parameter_last=parameter_temp;
parameter_temp=parameter_temp->next;
delete parameter_last;
}
delete parameter_temp;
}
delete parameter_temp;
statement_head->next=NULL;
parameter_head->next=NULL;
statement_temp=statement_head;
@ -295,7 +301,7 @@ parse::parse()
{
len=0;
content_array=new parse_unit[4096];
statement=new parse_unit[2048];
statement=new parse_unit[1024];
}
parse::~parse()
{
@ -310,17 +316,15 @@ void parse::content_array_set_empty()
{
content_array[i].line=0;
content_array[i].type=0;
content_array[i].content="";
}
return;
}
void parse::statement_set_empty()
{
for(int i=0;i<2048;++i)
for(int i=0;i<1024;++i)
{
statement[i].line=0;
statement[i].type=0;
statement[i].content="";
}
return;
}
@ -361,19 +365,35 @@ void parse::brace_check()
bool parse::def_function()
{
if(statement[0].content=="var" && statement[1].type==IDENTIFIER && statement[2].content=="=" && statement[3].content=="func")
{
func temp_func;
nasal_func_stack.append_function(statement[1].content,temp_func);
return true;
}
return false;
}
bool parse::def_array()
{
if(statement[0].content=="var" && statement[1].type==IDENTIFIER && statement[2].content=="=" && statement[3].content=="[")
if(statement[0].content=="var" && statement[1].type==IDENTIFIER && statement[2].content=="=" && statement[3].content=="[" && statement[4].content=="]")
{
var temp_var;
temp_var.type=VAR_LIST;
temp_var.data=new nasal_list;
nasal_var_stack.append_var(statement[1].content,temp_var);
return true;
}
return false;
}
bool parse::def_hash()
{
if(statement[0].content=="var" && statement[1].type==IDENTIFIER && statement[2].content=="=" && statement[3].content=="{")
if(statement[0].content=="var" && statement[1].type==IDENTIFIER && statement[2].content=="=" && statement[3].content=="{" && statement[4].content=="}")
{
var temp_var;
temp_var.type=VAR_HASH;
temp_var.data=new nasal_hash;
nasal_var_stack.append_var(statement[1].content,temp_var);
return true;
}
return false;
}
bool parse::def_scalar()

View File

@ -30,7 +30,9 @@ int main()
else if(command=="rs")
nasal::PrintSourceFile();
else if(command=="exit")
{
break;
}
else if(command=="lexer")
nasal::nasal_lexer.print();
else if(command=="del")

View File

@ -65,10 +65,10 @@ void PrintVar(var Var)
std::cout<<*((char *)Var.data);
else if(Var.type==VAR_STRING)
PrintString(*((std::string *)Var.data));
// else if(Var.type==VAR_LIST)
// ((NasalList *)Var.data)->PrintList();
// else if(Var.type==VAR_HASH)
// ((NasalHash *)Var.data)->PrintHash();
else if(Var.type==VAR_LIST)
;//((nasal_list *)Var.data)->print_list();
else if(Var.type==VAR_HASH)
;//((nasal_hash *)Var.data)->PrintHash();
else
std::cout<<"[Error] Null type or function";
}

View File

@ -25,18 +25,13 @@ class var_stack
{
var_stack_unit *temp=head;
var_stack_unit *this_node=NULL;
if(head->next)
while(temp->next)
{
while(temp->next)
{
this_node=temp;
temp=temp->next;
delete this_node;
}
delete temp;
this_node=temp;
temp=temp->next;
delete this_node;
}
else
delete head;
delete temp;
}
void append_var(std::string& varia_name,var& temp_var)
{