diff --git a/examples/test2.or b/examples/test2.or index 57fdc10..5d92323 100644 --- a/examples/test2.or +++ b/examples/test2.or @@ -3,11 +3,22 @@ a:="aa"*"bb" print("string: ", a, "\n") 32 a := -3+21+(-23) +aa:=1 +bb:=2 +cc:=3 +dd:=4 -x:=2+2.1 +x:=2+f(3,2) %해결해야할 오류... +print(x, "hello\n") +p:=2x+f(3,3) +print("variable p: ", p, "\n") print("hello\n") +q:=2x+f(3,3) +print("variable q: ", q, "\n") y:=((2+3)x+3)*2+f(3, 5) +print("hello\n") -print("variable a: ", a, "\n") +%print("variable a: ", a, f(3), "\n") %해결해야할 오류2 값 얻어서 나온 것 타입 print("variable x: ", x, "\n") print("variable y: ", y, "\n") +print("hello") diff --git a/examples/test3.or b/examples/test3.or index e5a5c64..70a900a 100644 --- a/examples/test3.or +++ b/examples/test3.or @@ -1,10 +1,9 @@ -a:=32 -satisfy a: a+2 -%a:=2 -%b:=7 -%q:=b+a-9 -%satisfy b: b+a-9 -%b:=7 -%print("vairable a: ", a, "\n") -a:=-2 -%print("vairable a: ", a, "\n") +f(x, y:=2):=3x+5+5y + +print(f(2,3)+2+2.1, "\n") +print(f(2,3)+2, "\n") + +%q:=2+f(2,3) +%x:=2+f(3,2) %해결해야할 오류... +%q:=x+f(3,5) +%print("@@@ ", q) diff --git a/src/Parser/Ast/ast.c b/src/Parser/Ast/ast.c index 25d166f..cced5c0 100644 --- a/src/Parser/Ast/ast.c +++ b/src/Parser/Ast/ast.c @@ -111,9 +111,10 @@ AST_string* init_ast_string(Token* token) AST_string* ast_string = (AST_string*) malloc(sizeof(struct ast_string_t)); ast_string->value = token->value; - char* real_value = malloc((strlen(token->value) - 2) * sizeof(char)); + char* real_value = malloc((strlen(token->value) - 1) * sizeof(char)); for (int i = 1; i < strlen(token->value) - 1; i ++) real_value[i - 1] = token->value[i]; + real_value[strlen(token->value) - 2] = '\0'; ast_string->real_value = real_value; ast_string->value_length = strlen(token->value); diff --git a/src/Visitor/visitor.c b/src/Visitor/visitor.c index ed2a9bf..fd2b91f 100644 --- a/src/Visitor/visitor.c +++ b/src/Visitor/visitor.c @@ -780,11 +780,11 @@ AST_value_stack* get_deep_copy_ast_value_stack new_value_stack->value = ast_value_stack->value; new_value_stack->next = ast_value_stack->next; - new_value_stack->col = ast_value_stack->col; - new_value_stack->col_first = ast_value_stack->col_first; - new_value_stack->row = ast_value_stack->row; - new_value_stack->row_char = ast_value_stack->row_char; - new_value_stack->row_char_first = ast_value_stack->row_char_first; +// new_value_stack->col = ast_value_stack->col; +// new_value_stack->col_first = ast_value_stack->col_first; +// new_value_stack->row = ast_value_stack->row; +// new_value_stack->row_char = ast_value_stack->row_char; +// new_value_stack->row_char_first = ast_value_stack->row_char_first; return new_value_stack; } @@ -799,8 +799,8 @@ AST_value_stack* visitor_get_value(Envs* envs, AST_value* ast_value) AST_value_stack* p = ast_value->stack; for (int i = max_cnt - 1; i >= 0; i --) { -// text_array[i] = get_deep_copy_ast_value_stack(p); - text_array[i] = p; + text_array[i] = get_deep_copy_ast_value_stack(p); +// text_array[i] = p; p = p->next; } @@ -893,6 +893,39 @@ AST_value_stack* visitor_get_value(Envs* envs, AST_value* ast_value) return parser_pop_value(stack); } +Env_variable* get_deep_copy_env_variable +(Env_variable* env_variable) +{ + Env_variable* new_env_variable = malloc(sizeof(Env_variable)); + + new_env_variable->name = env_variable->name; + new_env_variable->length = env_variable->length; + new_env_variable->type = env_variable->type; + new_env_variable->value = env_variable->value; + new_env_variable->satisfy_size = env_variable->satisfy_size; + new_env_variable->satisfy = env_variable->satisfy; + new_env_variable->next = env_variable->next; + + return new_env_variable; +} + +Env_function* get_deep_copy_env_funtion +(Env_function* env_function) +{ + Env_function* new_env_funtion = malloc(sizeof(Env_function)); + + new_env_funtion->name = env_function->name; + new_env_funtion->length = env_function->length; + new_env_funtion->args = env_function->args; + new_env_funtion->args_size = env_function->args_size; + new_env_funtion->codes = env_function->codes; + new_env_funtion->codes_size = env_function->codes_size; + new_env_funtion->type = env_function->type; + new_env_funtion->next = env_function->next; + + return new_env_funtion; +} + Envs* visitor_merge_envs(Envs* envs) { Env* global = envs->global; @@ -902,24 +935,32 @@ Envs* visitor_merge_envs(Envs* envs) new_global_env->variable_size = global->variable_size + local->variable_size; - new_global_env->variables = malloc(sizeof(struct env_variable_t)); + new_global_env->variables = get_deep_copy_env_variable(local->variables); // Warning! possibility error... - new_global_env->variables = local->variables; - + Env_variable* p_v = new_global_env->variables; while (p_v->next) - p_v = p_v->next; - p_v->next = global->variables; + { + Env_variable* new_env_variable = + get_deep_copy_env_variable(p_v); + p_v->next = new_env_variable; + p_v = new_env_variable->next; + } + p_v->next = get_deep_copy_env_variable(global->variables); new_global_env->function_size = global->function_size + local->function_size; - new_global_env->functions = malloc(sizeof(struct env_function_t)); - new_global_env->functions = local->functions; + new_global_env->functions = get_deep_copy_env_funtion(local->functions); Env_function* p_f = new_global_env->functions; while (p_f->next) - p_f = p_f->next; - p_f->next = global->functions; + { + Env_function* new_env_funtion = + get_deep_copy_env_funtion(p_f); + p_f->next = new_env_funtion; + p_f = new_env_funtion->next; + } + p_f->next = get_deep_copy_env_funtion(global->functions); Envs* new_envs = init_envs(new_global_env, init_env());