Bug in func& operator= fixed
This commit is contained in:
parent
d3db5019b5
commit
98dde4b53b
|
@ -26,18 +26,13 @@ class func_stack
|
||||||
{
|
{
|
||||||
func_stack_unit *temp=head;
|
func_stack_unit *temp=head;
|
||||||
func_stack_unit *this_node=NULL;
|
func_stack_unit *this_node=NULL;
|
||||||
if(head->next)
|
while(temp->next)
|
||||||
{
|
{
|
||||||
while(temp->next)
|
this_node=temp;
|
||||||
{
|
temp=temp->next;
|
||||||
this_node=temp;
|
delete this_node;
|
||||||
temp=temp->next;
|
|
||||||
delete this_node;
|
|
||||||
}
|
|
||||||
delete temp;
|
|
||||||
}
|
}
|
||||||
else
|
delete temp;
|
||||||
delete head;
|
|
||||||
}
|
}
|
||||||
void append_function(std::string &function_name,func &temp_func)
|
void append_function(std::string &function_name,func &temp_func)
|
||||||
{
|
{
|
||||||
|
@ -54,6 +49,7 @@ class func_stack
|
||||||
temp->next=new func_stack_unit;
|
temp->next=new func_stack_unit;
|
||||||
temp=temp->next;
|
temp=temp->next;
|
||||||
temp->next=NULL;
|
temp->next=NULL;
|
||||||
|
temp->func_name=function_name;
|
||||||
temp->func_statement=temp_func;
|
temp->func_statement=temp_func;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +76,6 @@ class func_stack
|
||||||
temp=temp->next;
|
temp=temp->next;
|
||||||
std::cout<<"function: "<<temp->func_name<<std::endl;
|
std::cout<<"function: "<<temp->func_name<<std::endl;
|
||||||
}
|
}
|
||||||
std::cout<<"function: "<<temp->func_name<<std::endl;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void pop_function()
|
void pop_function()
|
||||||
|
|
|
@ -122,27 +122,33 @@ func::~func()
|
||||||
}
|
}
|
||||||
func& func::operator=(const func& temp)
|
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;
|
token_unit *temp_state=temp.statement_head;
|
||||||
parameter *parameter_temp=parameter_head;
|
parameter *parameter_temp=parameter_head->next;
|
||||||
parameter *temp_param=temp.parameter_head;
|
parameter *temp_param=temp.parameter_head;
|
||||||
|
|
||||||
token_unit *statement_last=NULL;
|
token_unit *statement_last=NULL;
|
||||||
parameter *parameter_last=NULL;
|
parameter *parameter_last=NULL;
|
||||||
while(statement_temp->next)
|
if(statement_temp)
|
||||||
{
|
{
|
||||||
statement_last=statement_temp;
|
while(statement_temp->next)
|
||||||
statement_temp=statement_temp->next;
|
{
|
||||||
delete statement_last;
|
statement_last=statement_temp;
|
||||||
|
statement_temp=statement_temp->next;
|
||||||
|
delete statement_last;
|
||||||
|
}
|
||||||
|
delete statement_temp;
|
||||||
}
|
}
|
||||||
delete statement_temp;
|
if(parameter_temp)
|
||||||
while(parameter_temp->next)
|
|
||||||
{
|
{
|
||||||
parameter_last=parameter_temp;
|
while(parameter_temp->next)
|
||||||
parameter_temp=parameter_temp->next;
|
{
|
||||||
delete parameter_last;
|
parameter_last=parameter_temp;
|
||||||
|
parameter_temp=parameter_temp->next;
|
||||||
|
delete parameter_last;
|
||||||
|
}
|
||||||
|
delete parameter_temp;
|
||||||
}
|
}
|
||||||
delete parameter_temp;
|
|
||||||
statement_head->next=NULL;
|
statement_head->next=NULL;
|
||||||
parameter_head->next=NULL;
|
parameter_head->next=NULL;
|
||||||
statement_temp=statement_head;
|
statement_temp=statement_head;
|
||||||
|
@ -295,7 +301,7 @@ parse::parse()
|
||||||
{
|
{
|
||||||
len=0;
|
len=0;
|
||||||
content_array=new parse_unit[4096];
|
content_array=new parse_unit[4096];
|
||||||
statement=new parse_unit[2048];
|
statement=new parse_unit[1024];
|
||||||
}
|
}
|
||||||
parse::~parse()
|
parse::~parse()
|
||||||
{
|
{
|
||||||
|
@ -310,17 +316,15 @@ void parse::content_array_set_empty()
|
||||||
{
|
{
|
||||||
content_array[i].line=0;
|
content_array[i].line=0;
|
||||||
content_array[i].type=0;
|
content_array[i].type=0;
|
||||||
content_array[i].content="";
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void parse::statement_set_empty()
|
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].line=0;
|
||||||
statement[i].type=0;
|
statement[i].type=0;
|
||||||
statement[i].content="";
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -361,19 +365,35 @@ void parse::brace_check()
|
||||||
bool parse::def_function()
|
bool parse::def_function()
|
||||||
{
|
{
|
||||||
if(statement[0].content=="var" && statement[1].type==IDENTIFIER && statement[2].content=="=" && statement[3].content=="func")
|
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 true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool parse::def_array()
|
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 true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool parse::def_hash()
|
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 true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool parse::def_scalar()
|
bool parse::def_scalar()
|
||||||
|
|
|
@ -30,7 +30,9 @@ int main()
|
||||||
else if(command=="rs")
|
else if(command=="rs")
|
||||||
nasal::PrintSourceFile();
|
nasal::PrintSourceFile();
|
||||||
else if(command=="exit")
|
else if(command=="exit")
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
else if(command=="lexer")
|
else if(command=="lexer")
|
||||||
nasal::nasal_lexer.print();
|
nasal::nasal_lexer.print();
|
||||||
else if(command=="del")
|
else if(command=="del")
|
||||||
|
|
|
@ -65,10 +65,10 @@ void PrintVar(var Var)
|
||||||
std::cout<<*((char *)Var.data);
|
std::cout<<*((char *)Var.data);
|
||||||
else if(Var.type==VAR_STRING)
|
else if(Var.type==VAR_STRING)
|
||||||
PrintString(*((std::string *)Var.data));
|
PrintString(*((std::string *)Var.data));
|
||||||
// else if(Var.type==VAR_LIST)
|
else if(Var.type==VAR_LIST)
|
||||||
// ((NasalList *)Var.data)->PrintList();
|
;//((nasal_list *)Var.data)->print_list();
|
||||||
// else if(Var.type==VAR_HASH)
|
else if(Var.type==VAR_HASH)
|
||||||
// ((NasalHash *)Var.data)->PrintHash();
|
;//((nasal_hash *)Var.data)->PrintHash();
|
||||||
else
|
else
|
||||||
std::cout<<"[Error] Null type or function";
|
std::cout<<"[Error] Null type or function";
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,18 +25,13 @@ class var_stack
|
||||||
{
|
{
|
||||||
var_stack_unit *temp=head;
|
var_stack_unit *temp=head;
|
||||||
var_stack_unit *this_node=NULL;
|
var_stack_unit *this_node=NULL;
|
||||||
if(head->next)
|
while(temp->next)
|
||||||
{
|
{
|
||||||
while(temp->next)
|
this_node=temp;
|
||||||
{
|
temp=temp->next;
|
||||||
this_node=temp;
|
delete this_node;
|
||||||
temp=temp->next;
|
|
||||||
delete this_node;
|
|
||||||
}
|
|
||||||
delete temp;
|
|
||||||
}
|
}
|
||||||
else
|
delete temp;
|
||||||
delete head;
|
|
||||||
}
|
}
|
||||||
void append_var(std::string& varia_name,var& temp_var)
|
void append_var(std::string& varia_name,var& temp_var)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue