diff --git a/version0.2/nasal_func_stack.h b/version0.2/nasal_func_stack.h index 9753fd5..681f9f2 100644 --- a/version0.2/nasal_func_stack.h +++ b/version0.2/nasal_func_stack.h @@ -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: "<func_name<func_name<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() diff --git a/version0.2/nasal_interpreter.cpp b/version0.2/nasal_interpreter.cpp index 1c4dbd5..a3ed766 100644 --- a/version0.2/nasal_interpreter.cpp +++ b/version0.2/nasal_interpreter.cpp @@ -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") diff --git a/version0.2/nasal_print.h b/version0.2/nasal_print.h index 6a6b734..8e48a3e 100644 --- a/version0.2/nasal_print.h +++ b/version0.2/nasal_print.h @@ -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"; } diff --git a/version0.2/nasal_var_stack.h b/version0.2/nasal_var_stack.h index 8d97285..7965a3c 100644 --- a/version0.2/nasal_var_stack.h +++ b/version0.2/nasal_var_stack.h @@ -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) {