diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 328716ff..d99d8f33 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -5329,7 +5329,7 @@ static int deparse (ase_awk_t* awk) const ase_char_t* kw = ase_awk_getkw(awk,ASE_T("BEGIN")); if (ase_awk_putsrcstr(awk,kw) == -1) EXIT_DEPARSE (); if (ase_awk_putsrcstr (awk, ASE_T(" ")) == -1) EXIT_DEPARSE (); - if (ase_awk_prnpt (awk, nde) == -1) EXIT_DEPARSE (); + if (ase_awk_prnnde (awk, nde) == -1) EXIT_DEPARSE (); if (awk->option & ASE_AWK_CRLF) { @@ -5388,7 +5388,7 @@ static int deparse (ase_awk_t* awk) const ase_char_t* kw = ase_awk_getkw(awk,ASE_T("END")); if (ase_awk_putsrcstr(awk,kw) == -1) EXIT_DEPARSE (); if (ase_awk_putsrcstr (awk, ASE_T(" ")) == -1) EXIT_DEPARSE (); - if (ase_awk_prnpt (awk, nde) == -1) EXIT_DEPARSE (); + if (ase_awk_prnnde (awk, nde) == -1) EXIT_DEPARSE (); /* if (awk->option & ASE_AWK_CRLF) diff --git a/ase/awk/tree.c b/ase/awk/tree.c index 0c08f2b1..a424b564 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -565,346 +565,352 @@ static int print_expression_list (ase_awk_t* awk, ase_awk_nde_t* tree) return 0; } -static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth) +static int print_statement (ase_awk_t* awk, ase_awk_nde_t* p, int depth) { - ase_awk_nde_t* p = tree; ase_size_t i; - while (p != ASE_NULL) + switch (p->type) { - - switch (p->type) + case ASE_AWK_NDE_NULL: { - case ASE_AWK_NDE_NULL: + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ASE_T(";")); + PUT_NEWLINE (awk); + break; + } + + case ASE_AWK_NDE_BLK: + { + ase_size_t n; + ase_awk_nde_blk_t* px = (ase_awk_nde_blk_t*)p; + + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ASE_T("{")); + PUT_NEWLINE (awk); + + if (px->nlocals > 0) { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - break; - } + PRINT_TABS (awk, depth + 1); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("local"))); + PUT_SRCSTR (awk, ASE_T(" ")); - case ASE_AWK_NDE_BLK: - { - ase_size_t n; - ase_awk_nde_blk_t* px = (ase_awk_nde_blk_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("{")); - PUT_NEWLINE (awk); - - if (px->nlocals > 0) + for (i = 0; i < px->nlocals - 1; i++) { - PRINT_TABS (awk, depth + 1); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("local"))); - PUT_SRCSTR (awk, ASE_T(" ")); - - for (i = 0; i < px->nlocals - 1; i++) - { - PUT_SRCSTR (awk, ASE_T("__local")); - n = ase_awk_longtostr ( - i, 10, ASE_NULL, - awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt)); - PUT_SRCSTRX (awk, awk->tmp.fmt, n); - PUT_SRCSTR (awk, ASE_T(", ")); - } - PUT_SRCSTR (awk, ASE_T("__local")); n = ase_awk_longtostr ( i, 10, ASE_NULL, awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt)); PUT_SRCSTRX (awk, awk->tmp.fmt, n); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); + PUT_SRCSTR (awk, ASE_T(", ")); } - PRINT_STATEMENTS (awk, px->body, depth + 1); - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("}")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_IF: - { - ase_awk_nde_if_t* px = (ase_awk_nde_if_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("if"))); - PUT_SRCSTR (awk, ASE_T(" (")); - PRINT_EXPRESSION (awk, px->test); - PUT_SRCSTR (awk, ASE_T(")")); - PUT_NEWLINE (awk); - - ASE_ASSERT (px->then_part != ASE_NULL); - if (px->then_part->type == ASE_AWK_NDE_BLK) - PRINT_STATEMENTS (awk, px->then_part, depth); - else - PRINT_STATEMENTS (awk, px->then_part, depth + 1); - - if (px->else_part != ASE_NULL) - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("else"))); - PUT_NEWLINE (awk); - if (px->else_part->type == ASE_AWK_NDE_BLK) - PRINT_STATEMENTS (awk, px->else_part, depth); - else - PRINT_STATEMENTS (awk, px->else_part, depth + 1); - } - break; - } - - case ASE_AWK_NDE_WHILE: - { - ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("while"))); - PUT_SRCSTR (awk, ASE_T(" (")); - PRINT_EXPRESSION (awk, px->test); - PUT_SRCSTR (awk, ASE_T(")")); - PUT_NEWLINE (awk); - if (px->body->type == ASE_AWK_NDE_BLK) - { - PRINT_STATEMENTS (awk, px->body, depth); - } - else - { - PRINT_STATEMENTS (awk, px->body, depth + 1); - } - break; - } - - case ASE_AWK_NDE_DOWHILE: - { - ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("do"))); - PUT_NEWLINE (awk); - if (px->body->type == ASE_AWK_NDE_BLK) - { - PRINT_STATEMENTS (awk, px->body, depth); - } - else - { - PRINT_STATEMENTS (awk, px->body, depth + 1); - } - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("while"))); - PUT_SRCSTR (awk, ASE_T(" (")); - PRINT_EXPRESSION (awk, px->test); - PUT_SRCSTR (awk, ASE_T(");")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_FOR: - { - ase_awk_nde_for_t* px = (ase_awk_nde_for_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("for"))); - PUT_SRCSTR (awk, ASE_T(" (")); - if (px->init != ASE_NULL) - { - PRINT_EXPRESSION (awk, px->init); - } - PUT_SRCSTR (awk, ASE_T("; ")); - if (px->test != ASE_NULL) - { - PRINT_EXPRESSION (awk, px->test); - } - PUT_SRCSTR (awk, ASE_T("; ")); - if (px->incr != ASE_NULL) - { - PRINT_EXPRESSION (awk, px->incr); - } - PUT_SRCSTR (awk, ASE_T(")")); - PUT_NEWLINE (awk); - - if (px->body->type == ASE_AWK_NDE_BLK) - { - PRINT_STATEMENTS (awk, px->body, depth); - } - else - { - PRINT_STATEMENTS (awk, px->body, depth + 1); - } - break; - } - - case ASE_AWK_NDE_FOREACH: - { - ase_awk_nde_foreach_t* px = (ase_awk_nde_foreach_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("for"))); - PUT_SRCSTR (awk, ASE_T(" ")); - PRINT_EXPRESSION (awk, px->test); - PUT_NEWLINE (awk); - if (px->body->type == ASE_AWK_NDE_BLK) - { - PRINT_STATEMENTS (awk, px->body, depth); - } - else - { - PRINT_STATEMENTS (awk, px->body, depth + 1); - } - break; - } - - case ASE_AWK_NDE_BREAK: - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("break"))); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_CONTINUE: - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("continue"))); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_RETURN: - { - PRINT_TABS (awk, depth); - if (((ase_awk_nde_return_t*)p)->val == ASE_NULL) - { - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("return"))); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - } - else - { - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("return"))); - PUT_SRCSTR (awk, ASE_T(" ")); - ASE_ASSERT (((ase_awk_nde_return_t*)p)->val->next == ASE_NULL); - - PRINT_EXPRESSION (awk, ((ase_awk_nde_return_t*)p)->val); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - } - break; - } - - case ASE_AWK_NDE_EXIT: - { - ase_awk_nde_exit_t* px = (ase_awk_nde_exit_t*)p; - PRINT_TABS (awk, depth); - - if (px->val == ASE_NULL) - { - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("exit"))); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - } - else - { - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("exit"))); - PUT_SRCSTR (awk, ASE_T(" ")); - ASE_ASSERT (px->val->next == ASE_NULL); - PRINT_EXPRESSION (awk, px->val); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - } - break; - } - - case ASE_AWK_NDE_NEXT: - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("next"))); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_NEXTFILE: - { - PRINT_TABS (awk, depth); - if (((ase_awk_nde_nextfile_t*)p)->out) - { - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("nextofile"))); - } - else - { - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("nextfile"))); - } - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_DELETE: - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("delete"))); - PUT_SRCSTR (awk, ASE_T(" ")); - ase_awk_prnpt (awk, ((ase_awk_nde_delete_t*)p)->var); - break; - } - - case ASE_AWK_NDE_RESET: - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("reset"))); - PUT_SRCSTR (awk, ASE_T(" ")); - ase_awk_prnpt (awk, ((ase_awk_nde_reset_t*)p)->var); - break; - } - - case ASE_AWK_NDE_PRINT: - case ASE_AWK_NDE_PRINTF: - { - ase_awk_nde_print_t* px = (ase_awk_nde_print_t*)p; - - PRINT_TABS (awk, depth); - - if (p->type == ASE_AWK_NDE_PRINT) - { - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("print"))); - } - else - { - PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("printf"))); - } - - if (px->args != ASE_NULL) - { - PUT_SRCSTR (awk, ASE_T(" ")); - PRINT_EXPRESSION_LIST (awk, px->args); - } - - if (px->out != ASE_NULL) - { - PUT_SRCSTR (awk, ASE_T(" ")); - PUT_SRCSTR (awk, print_outop_str[px->out_type]); - PUT_SRCSTR (awk, ASE_T(" ")); - PRINT_EXPRESSION (awk, px->out); - } - - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - break; - } - - default: - { - PRINT_TABS (awk, depth); - PRINT_EXPRESSION (awk, p); + PUT_SRCSTR (awk, ASE_T("__local")); + n = ase_awk_longtostr ( + i, 10, ASE_NULL, + awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt)); + PUT_SRCSTRX (awk, awk->tmp.fmt, n); PUT_SRCSTR (awk, ASE_T(";")); PUT_NEWLINE (awk); } + + PRINT_STATEMENTS (awk, px->body, depth + 1); + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ASE_T("}")); + PUT_NEWLINE (awk); + break; } + case ASE_AWK_NDE_IF: + { + ase_awk_nde_if_t* px = (ase_awk_nde_if_t*)p; + + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("if"))); + PUT_SRCSTR (awk, ASE_T(" (")); + PRINT_EXPRESSION (awk, px->test); + PUT_SRCSTR (awk, ASE_T(")")); + PUT_NEWLINE (awk); + + ASE_ASSERT (px->then_part != ASE_NULL); + if (px->then_part->type == ASE_AWK_NDE_BLK) + PRINT_STATEMENTS (awk, px->then_part, depth); + else + PRINT_STATEMENTS (awk, px->then_part, depth + 1); + + if (px->else_part != ASE_NULL) + { + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("else"))); + PUT_NEWLINE (awk); + if (px->else_part->type == ASE_AWK_NDE_BLK) + PRINT_STATEMENTS (awk, px->else_part, depth); + else + PRINT_STATEMENTS (awk, px->else_part, depth + 1); + } + break; + } + + case ASE_AWK_NDE_WHILE: + { + ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p; + + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("while"))); + PUT_SRCSTR (awk, ASE_T(" (")); + PRINT_EXPRESSION (awk, px->test); + PUT_SRCSTR (awk, ASE_T(")")); + PUT_NEWLINE (awk); + if (px->body->type == ASE_AWK_NDE_BLK) + { + PRINT_STATEMENTS (awk, px->body, depth); + } + else + { + PRINT_STATEMENTS (awk, px->body, depth + 1); + } + break; + } + + case ASE_AWK_NDE_DOWHILE: + { + ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p; + + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("do"))); + PUT_NEWLINE (awk); + if (px->body->type == ASE_AWK_NDE_BLK) + { + PRINT_STATEMENTS (awk, px->body, depth); + } + else + { + PRINT_STATEMENTS (awk, px->body, depth + 1); + } + + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("while"))); + PUT_SRCSTR (awk, ASE_T(" (")); + PRINT_EXPRESSION (awk, px->test); + PUT_SRCSTR (awk, ASE_T(");")); + PUT_NEWLINE (awk); + break; + } + + case ASE_AWK_NDE_FOR: + { + ase_awk_nde_for_t* px = (ase_awk_nde_for_t*)p; + + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("for"))); + PUT_SRCSTR (awk, ASE_T(" (")); + if (px->init != ASE_NULL) + { + PRINT_EXPRESSION (awk, px->init); + } + PUT_SRCSTR (awk, ASE_T("; ")); + if (px->test != ASE_NULL) + { + PRINT_EXPRESSION (awk, px->test); + } + PUT_SRCSTR (awk, ASE_T("; ")); + if (px->incr != ASE_NULL) + { + PRINT_EXPRESSION (awk, px->incr); + } + PUT_SRCSTR (awk, ASE_T(")")); + PUT_NEWLINE (awk); + + if (px->body->type == ASE_AWK_NDE_BLK) + { + PRINT_STATEMENTS (awk, px->body, depth); + } + else + { + PRINT_STATEMENTS (awk, px->body, depth + 1); + } + break; + } + + case ASE_AWK_NDE_FOREACH: + { + ase_awk_nde_foreach_t* px = (ase_awk_nde_foreach_t*)p; + + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("for"))); + PUT_SRCSTR (awk, ASE_T(" ")); + PRINT_EXPRESSION (awk, px->test); + PUT_NEWLINE (awk); + if (px->body->type == ASE_AWK_NDE_BLK) + { + PRINT_STATEMENTS (awk, px->body, depth); + } + else + { + PRINT_STATEMENTS (awk, px->body, depth + 1); + } + break; + } + + case ASE_AWK_NDE_BREAK: + { + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("break"))); + PUT_SRCSTR (awk, ASE_T(";")); + PUT_NEWLINE (awk); + break; + } + + case ASE_AWK_NDE_CONTINUE: + { + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("continue"))); + PUT_SRCSTR (awk, ASE_T(";")); + PUT_NEWLINE (awk); + break; + } + + case ASE_AWK_NDE_RETURN: + { + PRINT_TABS (awk, depth); + if (((ase_awk_nde_return_t*)p)->val == ASE_NULL) + { + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("return"))); + PUT_SRCSTR (awk, ASE_T(";")); + PUT_NEWLINE (awk); + } + else + { + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("return"))); + PUT_SRCSTR (awk, ASE_T(" ")); + ASE_ASSERT (((ase_awk_nde_return_t*)p)->val->next == ASE_NULL); + + PRINT_EXPRESSION (awk, ((ase_awk_nde_return_t*)p)->val); + PUT_SRCSTR (awk, ASE_T(";")); + PUT_NEWLINE (awk); + } + break; + } + + case ASE_AWK_NDE_EXIT: + { + ase_awk_nde_exit_t* px = (ase_awk_nde_exit_t*)p; + PRINT_TABS (awk, depth); + + if (px->val == ASE_NULL) + { + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("exit"))); + PUT_SRCSTR (awk, ASE_T(";")); + PUT_NEWLINE (awk); + } + else + { + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("exit"))); + PUT_SRCSTR (awk, ASE_T(" ")); + ASE_ASSERT (px->val->next == ASE_NULL); + PRINT_EXPRESSION (awk, px->val); + PUT_SRCSTR (awk, ASE_T(";")); + PUT_NEWLINE (awk); + } + break; + } + + case ASE_AWK_NDE_NEXT: + { + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("next"))); + PUT_SRCSTR (awk, ASE_T(";")); + PUT_NEWLINE (awk); + break; + } + + case ASE_AWK_NDE_NEXTFILE: + { + PRINT_TABS (awk, depth); + if (((ase_awk_nde_nextfile_t*)p)->out) + { + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("nextofile"))); + } + else + { + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("nextfile"))); + } + PUT_SRCSTR (awk, ASE_T(";")); + PUT_NEWLINE (awk); + break; + } + + case ASE_AWK_NDE_DELETE: + { + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("delete"))); + PUT_SRCSTR (awk, ASE_T(" ")); + ase_awk_prnpt (awk, ((ase_awk_nde_delete_t*)p)->var); + break; + } + + case ASE_AWK_NDE_RESET: + { + PRINT_TABS (awk, depth); + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("reset"))); + PUT_SRCSTR (awk, ASE_T(" ")); + ase_awk_prnpt (awk, ((ase_awk_nde_reset_t*)p)->var); + break; + } + + case ASE_AWK_NDE_PRINT: + case ASE_AWK_NDE_PRINTF: + { + ase_awk_nde_print_t* px = (ase_awk_nde_print_t*)p; + + PRINT_TABS (awk, depth); + + if (p->type == ASE_AWK_NDE_PRINT) + { + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("print"))); + } + else + { + PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("printf"))); + } + + if (px->args != ASE_NULL) + { + PUT_SRCSTR (awk, ASE_T(" ")); + PRINT_EXPRESSION_LIST (awk, px->args); + } + + if (px->out != ASE_NULL) + { + PUT_SRCSTR (awk, ASE_T(" ")); + PUT_SRCSTR (awk, print_outop_str[px->out_type]); + PUT_SRCSTR (awk, ASE_T(" ")); + PRINT_EXPRESSION (awk, px->out); + } + + PUT_SRCSTR (awk, ASE_T(";")); + PUT_NEWLINE (awk); + break; + } + + default: + { + PRINT_TABS (awk, depth); + PRINT_EXPRESSION (awk, p); + PUT_SRCSTR (awk, ASE_T(";")); + PUT_NEWLINE (awk); + } + } + + return 0; +} + +static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth) +{ + ase_awk_nde_t* p = tree; + + while (p != ASE_NULL) + { + if (print_statement (awk, p, depth) == -1) return -1; p = p->next; } @@ -916,6 +922,11 @@ int ase_awk_prnpt (ase_awk_t* awk, ase_awk_nde_t* tree) return print_statements (awk, tree, 0); } +int ase_awk_prnnde (ase_awk_t* awk, ase_awk_nde_t* tree) +{ + return print_statement (awk, tree, 0); +} + int ase_awk_prnptnpt (ase_awk_t* awk, ase_awk_nde_t* tree) { ase_awk_nde_t* nde = tree; diff --git a/ase/awk/tree.h b/ase/awk/tree.h index 6b66fefe..f4ee68c7 100644 --- a/ase/awk/tree.h +++ b/ase/awk/tree.h @@ -408,7 +408,11 @@ struct ase_awk_nde_print_t extern "C" { #endif +/* print the entire tree */ int ase_awk_prnpt (ase_awk_t* awk, ase_awk_nde_t* tree); +/* print a single top-level node */ +int ase_awk_prnnde (ase_awk_t* awk, ase_awk_nde_t* node); +/* print the pattern part */ int ase_awk_prnptnpt (ase_awk_t* awk, ase_awk_nde_t* tree); void ase_awk_clrpt (ase_awk_t* awk, ase_awk_nde_t* tree); diff --git a/ase/test/awk/main-001.out b/ase/test/awk/main-001.out new file mode 100644 index 00000000..d8006685 --- /dev/null +++ b/ase/test/awk/main-001.out @@ -0,0 +1,7 @@ +function main () +{ + x = 0; + y = 0; + return 999; +} + diff --git a/ase/test/awk/main-002.awk b/ase/test/awk/main-002.awk index f729fd84..e9cea6b3 100644 --- a/ase/test/awk/main-002.awk +++ b/ase/test/awk/main-002.awk @@ -1,36 +1,36 @@ - function error() { exit (200); } - function getx() - { - if (x == 2) error(); - return x++; - } +function error() { exit (200); } +function getx() +{ + if (x == 2) error(); + return x++; +} - function gety() { return y++; } +function gety() { return y++; } - function main() { - x = 0; - y = 0; - print getx() + gety(); - print getx() + gety(); - print getx() + gety(); - print getx() + gety(); +function main() { + x = 0; + y = 0; + print getx() + gety(); + print getx() + gety(); + print getx() + gety(); + print getx() + gety(); - return 999; - } + return 999; +} - END { - print "END OF PROGRAM"; - return 10; - } +END { + print "END OF PROGRAM"; + return 10; +} - END { - print "END OF PROGRAM 2"; - exit (100); - } +END { + print "END OF PROGRAM 2"; + exit (100); +} - END { - print "END OF PROGRAM 3"; - exit (900); - } +END { + print "END OF PROGRAM 3"; + exit (900); +} diff --git a/ase/test/awk/main-002.out b/ase/test/awk/main-002.out new file mode 100644 index 00000000..cb5fb5b1 --- /dev/null +++ b/ase/test/awk/main-002.out @@ -0,0 +1,42 @@ +function error () +{ + exit 200; +} + +function getx () +{ + if ((x == 2)) + error (); + return (x)++; +} + +function gety () +{ + return (y)++; +} + +function main () +{ + x = 0; + y = 0; + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); + return 999; +} + +END { + print "END OF PROGRAM"; + return 10; +} +END { + print "END OF PROGRAM 2"; + exit 100; +} +END { + print "END OF PROGRAM 3"; + exit 900; +} +0 +2 diff --git a/ase/test/awk/regress.sh b/ase/test/awk/regress.sh index 6209c4a8..89e88869 100755 --- a/ase/test/awk/regress.sh +++ b/ase/test/awk/regress.sh @@ -11,8 +11,34 @@ run_script_for_init() "$ASEAWK" $OPTION -d -f "$script" "$data" > "$output" } +run_script_for_init_nodata() +{ + script="$1" + output=`echo $script | sed 's/\.awk$/.out/g'` + + "$ASEAWK" $OPTION -d -f "$script" > "$output" +} + +run_script_for_init_main() +{ + script="$1" + output=`echo $script | sed 's/\.awk$/.out/g'` + + "$ASEAWK" $OPTION -m main -d -f "$script" > "$output" +} + run_init() { + for script in simple-???.awk + do + run_script_for_init_nodata "$script" + done + + for script in main-???.awk + do + run_script_for_init_main "$script" + done + for script in emp-???.awk do run_script_for_init "$script" "emp-en.data" @@ -55,10 +81,86 @@ run_script_for_test() return 0 } +run_script_for_test_nodata() +{ + script="$1" + output=`echo $script | sed 's/\.awk$/.out/g'` + + echo ">> RUNNING $script" + "$ASEAWK" $OPTION -d -f "$script" > "$output.$pid" + + #diff -y "$output" "$output.$pid" + diff "$output" "$output.$pid" + if [ $? -ne 0 ] + then + rm -f "$output.$pid" + return 1 + fi + + rm -f "$output.$pid" + return 0 +} + +run_script_for_test_main() +{ + script="$1" + output=`echo $script | sed 's/\.awk$/.out/g'` + + echo ">> RUNNING $script" + "$ASEAWK" $OPTION -m main -d -f "$script" > "$output.$pid" + + #diff -y "$output" "$output.$pid" + diff "$output" "$output.$pid" + if [ $? -ne 0 ] + then + rm -f "$output.$pid" + return 1 + fi + + rm -f "$output.$pid" + return 0 +} + run_test() { pid=$$ + for script in simple-???.awk + do + run_script_for_test_nodata "$script" + if [ $? -ne 0 ] + then + echo "###################################" + echo "PROBLEM(S) DETECTED IN $script.". + echo "###################################" + + echo "Do you want to abort? [y/n]" + read ans + if [ "$ans" = "y" -o "$ans" = "Y" ] + then + return 1 + fi + fi + done + + for script in main-???.awk + do + run_script_for_test_main "$script" + if [ $? -ne 0 ] + then + echo "###################################" + echo "PROBLEM(S) DETECTED IN $script.". + echo "###################################" + + echo "Do you want to abort? [y/n]" + read ans + if [ "$ans" = "y" -o "$ans" = "Y" ] + then + return 1 + fi + fi + done + for script in emp-???.awk do run_script_for_test "$script" "emp-en.data" diff --git a/ase/test/awk/simple-001.out b/ase/test/awk/simple-001.out new file mode 100644 index 00000000..98adc277 --- /dev/null +++ b/ase/test/awk/simple-001.out @@ -0,0 +1,28 @@ +function error () +{ + exit 200; +} + +function getx () +{ + if ((x == 2)) + error (); + return (x)++; +} + +function gety () +{ + return (y)++; +} + +BEGIN { + x = 0; + y = 0; + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); +} + +0 +2 diff --git a/ase/test/awk/simple-002.out b/ase/test/awk/simple-002.out new file mode 100644 index 00000000..07fbf211 --- /dev/null +++ b/ase/test/awk/simple-002.out @@ -0,0 +1,32 @@ +function error () +{ + exit 200; +} + +function getx () +{ + if ((x == 2)) + error (); + return (x)++; +} + +function gety () +{ + return (y)++; +} + +BEGIN { + x = 0; + y = 0; + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); +} + +END { + print "END OF PROGRAM"; +} +0 +2 +END OF PROGRAM diff --git a/ase/test/awk/simple-003.out b/ase/test/awk/simple-003.out new file mode 100644 index 00000000..2f95cb41 --- /dev/null +++ b/ase/test/awk/simple-003.out @@ -0,0 +1,33 @@ +function error () +{ + exit 200; +} + +function getx () +{ + if ((x == 2)) + error (); + return (x)++; +} + +function gety () +{ + return (y)++; +} + +BEGIN { + x = 0; + y = 0; + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); +} + +END { + print "END OF PROGRAM"; + exit 20; +} +0 +2 +END OF PROGRAM diff --git a/ase/test/awk/simple-004.out b/ase/test/awk/simple-004.out new file mode 100644 index 00000000..747dd794 --- /dev/null +++ b/ase/test/awk/simple-004.out @@ -0,0 +1,36 @@ +function error () +{ + exit 200; +} + +function getx () +{ + if ((x == 2)) + error (); + return (x)++; +} + +function gety () +{ + return (y)++; +} + +BEGIN { + x = 0; + y = 0; + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); +} + +END { + print "END OF PROGRAM"; + exit 20; +} +END { + print "END OF PROGRAM 2"; +} +0 +2 +END OF PROGRAM diff --git a/ase/test/awk/simple-005.out b/ase/test/awk/simple-005.out new file mode 100644 index 00000000..2161f0bd --- /dev/null +++ b/ase/test/awk/simple-005.out @@ -0,0 +1,38 @@ +function error () +{ + exit 200; +} + +function getx () +{ + if ((x == 2)) + error (); + return (x)++; +} + +function gety () +{ + return (y)++; +} + +BEGIN { + x = 0; + y = 0; + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); +} + +END { + print "END OF PROGRAM"; + return 10; +} +END { + print "END OF PROGRAM 2"; + return 20; +} +0 +2 +END OF PROGRAM +END OF PROGRAM 2 diff --git a/ase/test/awk/simple-006.out b/ase/test/awk/simple-006.out new file mode 100644 index 00000000..2639d36a --- /dev/null +++ b/ase/test/awk/simple-006.out @@ -0,0 +1,42 @@ +function error () +{ + exit 200; +} + +function getx () +{ + if ((x == 2)) + error (); + return (x)++; +} + +function gety () +{ + return (y)++; +} + +BEGIN { + x = 0; + y = 0; + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); + print (getx () + gety ()); +} + +END { + print "END OF PROGRAM"; + return 10; +} +END { + print "END OF PROGRAM 2"; + exit 100; +} +END { + print "END OF PROGRAM 3"; + exit 900; +} +0 +2 +END OF PROGRAM +END OF PROGRAM 2