From 4b54877ee9c7d714fd5675f2c87108c7d679949c Mon Sep 17 00:00:00 2001 From: Riley Smith Date: Fri, 15 Nov 2024 13:44:20 -0800 Subject: [PATCH] update tests --- lab-5/expr.c | 7 +++++++ lab-5/main_test.c | 14 +++++--------- lab-5/parser.bison | 7 +++---- lab-5/samples/hello-world_evaluate.txt | 1 + lab-5/samples/hello-world_print.txt | 5 +++++ 5 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 lab-5/samples/hello-world_evaluate.txt create mode 100644 lab-5/samples/hello-world_print.txt diff --git a/lab-5/expr.c b/lab-5/expr.c index 45c7592..13fb759 100644 --- a/lab-5/expr.c +++ b/lab-5/expr.c @@ -159,6 +159,13 @@ void stmt_print(struct stmt *s) { decl_print(s->decl); printf(";\n"); break; + case STMT_MOVE: + printf("move "); + expr_print(s->decl->name); + printf(" to "); + expr_print(s->decl->value); + printf(";\n"); + break; case STMT_END_EXECUTION: printf("stop run\n"); break; diff --git a/lab-5/main_test.c b/lab-5/main_test.c index 4b1ec9f..41d5840 100644 --- a/lab-5/main_test.c +++ b/lab-5/main_test.c @@ -117,14 +117,10 @@ UTEST_F_TEARDOWN(InterpreterTestFile) { ASSERT_STREQ(actual_evaluate, expected_evaluate); } -UTEST_F(InterpreterTestFile, print) { - utest_fixture->test_file = "samples/multiple_statements.c"; - utest_fixture->print_file = "samples/multiple_statements_print.txt"; - utest_fixture->evaluated_file = "samples/multiple_statements_evaluate.txt"; +UTEST_F(InterpreterTestFile, helloworld) { + utest_fixture->test_file = "samples/hello-world.cbl"; + utest_fixture->print_file = "samples/hello-world_print.txt"; + utest_fixture->evaluated_file = "samples/hello-world_evaluate.txt"; } -UTEST_F(InterpreterTestFile, program_file) { - utest_fixture->test_file = "samples/program.c"; - utest_fixture->print_file = "samples/program_print.txt"; - utest_fixture->evaluated_file = "samples/program_evaluate.txt"; -} + diff --git a/lab-5/parser.bison b/lab-5/parser.bison index ea9889f..f5d4518 100644 --- a/lab-5/parser.bison +++ b/lab-5/parser.bison @@ -83,7 +83,6 @@ extern struct stmt *parser_result = 0; %token TOKEN_EXPONENTIAL %token TOKEN_DISPLAY - %left TOKEN_ADD TOKEN_SUB %left TOKEN_MULTIPLY TOKEN_DIVIDE %left TOKEN_EXPONENTIAL @@ -137,9 +136,10 @@ type : TOKEN_KEYWORD_IDENTIFICATION simple_stmt : cbl_func_stmt {$$ = $1;} | if_branch + {$$ = $1;} | perform_stmt ; -cbl_func_stmt : cbl_function ident assignment_stmt +cbl_func_stmt : cbl_function type_expr assignment_stmt { $3->name = $2; $$= stmt_create($1->kind, $3, NULL, NULL, NULL, NULL, NULL, NULL);} | cbl_function op_parms {$$ = stmt_create($1->kind, NULL, NULL, $2, NULL, NULL, NULL, NULL);} @@ -200,7 +200,6 @@ type_expr : ident {$$ = expr_create_string_literal(yytext);} | TOKEN_SPACE {$$ = expr_create_integer_literal(0);} - // TODO: implment negative numbers | TOKEN_SUB ident { $2->negative = 1; $$ = $2;} | ext_function @@ -271,7 +270,7 @@ category_value : TOKEN_KEYWORD_VALUE TOKEN_INTEGER category_spec : complete_category {$$ = decl_create(NULL, $1, NULL, NULL, NULL);} | complete_category data_clause category_value - { $$ = decl_create(NULL, $1, $3, NULL, $2);} + { $1->level = $2->level; $$ = decl_create(NULL, $1, $3, NULL, NULL);} ; //TODO: implement levels simple_decl : TOKEN_INTEGER ident TOKEN_DOT diff --git a/lab-5/samples/hello-world_evaluate.txt b/lab-5/samples/hello-world_evaluate.txt new file mode 100644 index 0000000..980a0d5 --- /dev/null +++ b/lab-5/samples/hello-world_evaluate.txt @@ -0,0 +1 @@ +Hello World! diff --git a/lab-5/samples/hello-world_print.txt b/lab-5/samples/hello-world_print.txt new file mode 100644 index 0000000..4bd27ce --- /dev/null +++ b/lab-5/samples/hello-world_print.txt @@ -0,0 +1,5 @@ +section +section +section +print Hello World!; +stop run