From 3c9384a631bd8fa5df0ad9a4aea44481fc09b07a Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 3 Mar 2006 11:45:45 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk.h | 13 +- ase/awk/parse.c | 768 ++++++++++++++++++++++++------------------------ ase/awk/run.c | 130 ++++---- ase/awk/sa.h | 5 +- ase/awk/tree.c | 364 +++++++++++------------ ase/awk/tree.h | 196 ++++++------ ase/awk/val.h | 44 +++ 7 files changed, 799 insertions(+), 721 deletions(-) create mode 100644 ase/awk/val.h diff --git a/ase/awk/awk.h b/ase/awk/awk.h index 3c9672c2..1e48db8f 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.30 2006-03-02 15:10:59 bacon Exp $ + * $Id: awk.h,v 1.31 2006-03-03 11:45:45 bacon Exp $ */ #ifndef _XP_AWK_AWK_H_ @@ -16,6 +16,7 @@ #include #include #include +#include enum { @@ -39,7 +40,7 @@ enum XP_AWK_EEXPR, /* expression expected */ XP_AWK_EWHILE, /* keyword 'while' is expected */ - XP_AWK_EASSIGN, /* assignment statement expected */ + XP_AWK_EASSIGNMENT, /* assignment statement expected */ XP_AWK_EIDENT, /* identifier expected */ XP_AWK_EDUPBEGIN, /* duplicate BEGIN */ XP_AWK_EDUPEND, /* duplicate END */ @@ -103,8 +104,8 @@ struct xp_awk_t { xp_size_t nglobals; xp_awk_map_t funcs; - xp_awk_node_t* begin; - xp_awk_node_t* end; + xp_awk_nde_t* begin; + xp_awk_nde_t* end; xp_awk_chain_t* chain; xp_awk_chain_t* chain_tail; } tree; @@ -146,8 +147,8 @@ struct xp_awk_t struct xp_awk_chain_t { - xp_awk_node_t* pattern; - xp_awk_node_t* action; + xp_awk_nde_t* pattern; + xp_awk_nde_t* action; xp_awk_chain_t* next; }; diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 3cf30a51..e2e9b63d 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.54 2006-03-02 15:10:59 bacon Exp $ + * $Id: parse.c,v 1.55 2006-03-03 11:45:45 bacon Exp $ */ #include @@ -100,36 +100,36 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk); static xp_awk_t* __collect_globals (xp_awk_t* awk); static xp_awk_t* __collect_locals (xp_awk_t* awk, xp_size_t nlocals); -static xp_awk_node_t* __parse_function (xp_awk_t* awk); -static xp_awk_node_t* __parse_begin (xp_awk_t* awk); -static xp_awk_node_t* __parse_end (xp_awk_t* awk); -static xp_awk_node_t* __parse_patternless (xp_awk_t* awk); +static xp_awk_nde_t* __parse_function (xp_awk_t* awk); +static xp_awk_nde_t* __parse_begin (xp_awk_t* awk); +static xp_awk_nde_t* __parse_end (xp_awk_t* awk); +static xp_awk_nde_t* __parse_patternless (xp_awk_t* awk); -static xp_awk_node_t* __parse_action (xp_awk_t* awk); -static xp_awk_node_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top); -static xp_awk_node_t* __parse_statement (xp_awk_t* awk); -static xp_awk_node_t* __parse_statement_nb (xp_awk_t* awk); -static xp_awk_node_t* __parse_expression (xp_awk_t* awk); -static xp_awk_node_t* __parse_basic_expr (xp_awk_t* awk); -static xp_awk_node_t* __parse_equality (xp_awk_t* awk); -static xp_awk_node_t* __parse_relational (xp_awk_t* awk); -static xp_awk_node_t* __parse_shift (xp_awk_t* awk); -static xp_awk_node_t* __parse_additive (xp_awk_t* awk); -static xp_awk_node_t* __parse_multiplicative (xp_awk_t* awk); -static xp_awk_node_t* __parse_unary (xp_awk_t* awk); -static xp_awk_node_t* __parse_primary (xp_awk_t* awk); -static xp_awk_node_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name); -static xp_awk_node_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name); -static xp_awk_node_t* __parse_if (xp_awk_t* awk); -static xp_awk_node_t* __parse_while (xp_awk_t* awk); -static xp_awk_node_t* __parse_for (xp_awk_t* awk); -static xp_awk_node_t* __parse_dowhile (xp_awk_t* awk); -static xp_awk_node_t* __parse_break (xp_awk_t* awk); -static xp_awk_node_t* __parse_continue (xp_awk_t* awk); -static xp_awk_node_t* __parse_return (xp_awk_t* awk); -static xp_awk_node_t* __parse_exit (xp_awk_t* awk); -static xp_awk_node_t* __parse_next (xp_awk_t* awk); -static xp_awk_node_t* __parse_nextfile (xp_awk_t* awk); +static xp_awk_nde_t* __parse_action (xp_awk_t* awk); +static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top); +static xp_awk_nde_t* __parse_statement (xp_awk_t* awk); +static xp_awk_nde_t* __parse_statement_nb (xp_awk_t* awk); +static xp_awk_nde_t* __parse_expression (xp_awk_t* awk); +static xp_awk_nde_t* __parse_basic_expr (xp_awk_t* awk); +static xp_awk_nde_t* __parse_equality (xp_awk_t* awk); +static xp_awk_nde_t* __parse_relational (xp_awk_t* awk); +static xp_awk_nde_t* __parse_shift (xp_awk_t* awk); +static xp_awk_nde_t* __parse_additive (xp_awk_t* awk); +static xp_awk_nde_t* __parse_multiplicative (xp_awk_t* awk); +static xp_awk_nde_t* __parse_unary (xp_awk_t* awk); +static xp_awk_nde_t* __parse_primary (xp_awk_t* awk); +static xp_awk_nde_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name); +static xp_awk_nde_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name); +static xp_awk_nde_t* __parse_if (xp_awk_t* awk); +static xp_awk_nde_t* __parse_while (xp_awk_t* awk); +static xp_awk_nde_t* __parse_for (xp_awk_t* awk); +static xp_awk_nde_t* __parse_dowhile (xp_awk_t* awk); +static xp_awk_nde_t* __parse_break (xp_awk_t* awk); +static xp_awk_nde_t* __parse_continue (xp_awk_t* awk); +static xp_awk_nde_t* __parse_return (xp_awk_t* awk); +static xp_awk_nde_t* __parse_exit (xp_awk_t* awk); +static xp_awk_nde_t* __parse_next (xp_awk_t* awk); +static xp_awk_nde_t* __parse_nextfile (xp_awk_t* awk); static int __get_token (xp_awk_t* awk); static int __get_char (xp_awk_t* awk); @@ -332,11 +332,11 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk) return awk; } -static xp_awk_node_t* __parse_function (xp_awk_t* awk) +static xp_awk_nde_t* __parse_function (xp_awk_t* awk) { xp_char_t* name; xp_char_t* name_dup; - xp_awk_node_t* body; + xp_awk_nde_t* body; xp_awk_func_t* func; xp_size_t nargs; @@ -513,50 +513,50 @@ static xp_awk_node_t* __parse_function (xp_awk_t* awk) return body; } -static xp_awk_node_t* __parse_begin (xp_awk_t* awk) +static xp_awk_nde_t* __parse_begin (xp_awk_t* awk) { - xp_awk_node_t* node; + xp_awk_nde_t* nde; if (awk->tree.begin != XP_NULL) PANIC (awk, XP_AWK_EDUPBEGIN); if (__get_token(awk) == -1) return XP_NULL; - node = __parse_action (awk); - if (node == XP_NULL) return XP_NULL; + nde = __parse_action (awk); + if (nde == XP_NULL) return XP_NULL; - awk->tree.begin = node; - return node; + awk->tree.begin = nde; + return nde; } -static xp_awk_node_t* __parse_end (xp_awk_t* awk) +static xp_awk_nde_t* __parse_end (xp_awk_t* awk) { - xp_awk_node_t* node; + xp_awk_nde_t* nde; if (awk->tree.end != XP_NULL) PANIC (awk, XP_AWK_EDUPEND); if (__get_token(awk) == -1) return XP_NULL; - node = __parse_action (awk); - if (node == XP_NULL) return XP_NULL; + nde = __parse_action (awk); + if (nde == XP_NULL) return XP_NULL; - awk->tree.end = node; - return node; + awk->tree.end = nde; + return nde; } -static xp_awk_node_t* __parse_patternless (xp_awk_t* awk) +static xp_awk_nde_t* __parse_patternless (xp_awk_t* awk) { - xp_awk_node_t* node; + xp_awk_nde_t* nde; xp_awk_chain_t* chain; - node = __parse_action (awk); - if (node == XP_NULL) return XP_NULL; + nde = __parse_action (awk); + if (nde == XP_NULL) return XP_NULL; chain = (xp_awk_chain_t*) xp_malloc (xp_sizeof(xp_awk_chain_t)); if (chain == XP_NULL) { - xp_awk_clrpt (node); + xp_awk_clrpt (nde); PANIC (awk, XP_AWK_ENOMEM); } chain->pattern = XP_NULL; - chain->action = node; + chain->action = nde; chain->next = XP_NULL; if (awk->tree.chain == XP_NULL) { @@ -568,20 +568,20 @@ static xp_awk_node_t* __parse_patternless (xp_awk_t* awk) awk->tree.chain_tail = chain; } - return node; + return nde; } -static xp_awk_node_t* __parse_action (xp_awk_t* awk) +static xp_awk_nde_t* __parse_action (xp_awk_t* awk) { if (!MATCH(awk,TOKEN_LBRACE)) PANIC (awk, XP_AWK_ELBRACE); if (__get_token(awk) == -1) return XP_NULL; return __parse_block(awk, xp_true); } -static xp_awk_node_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top) +static xp_awk_nde_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top) { - xp_awk_node_t* head, * curr, * node; - xp_awk_node_block_t* block; + xp_awk_nde_t* head, * curr, * nde; + xp_awk_nde_block_t* block; xp_size_t nlocals, nlocals_max, tmp; nlocals = xp_awk_tab_getsize(&awk->parse.locals); @@ -631,8 +631,8 @@ static xp_awk_node_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top) break; } - node = __parse_statement (awk); - if (node == XP_NULL) { + nde = __parse_statement (awk); + if (nde == XP_NULL) { xp_awk_tab_remrange ( &awk->parse.locals, nlocals, xp_awk_tab_getsize(&awk->parse.locals) - nlocals); @@ -641,16 +641,16 @@ static xp_awk_node_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top) } /* remove unnecessary statements */ - if (node->type == XP_AWK_NODE_NULL || - (node->type == XP_AWK_NODE_BLOCK && - ((xp_awk_node_block_t*)node)->body == XP_NULL)) continue; + if (nde->type == XP_AWK_NDE_NULL || + (nde->type == XP_AWK_NDE_BLOCK && + ((xp_awk_nde_block_t*)nde)->body == XP_NULL)) continue; - if (curr == XP_NULL) head = node; - else curr->next = node; - curr = node; + if (curr == XP_NULL) head = nde; + else curr->next = nde; + curr = nde; } - block = (xp_awk_node_block_t*) xp_malloc (xp_sizeof(xp_awk_node_block_t)); + block = (xp_awk_nde_block_t*) xp_malloc (xp_sizeof(xp_awk_nde_block_t)); if (block == XP_NULL) { xp_awk_tab_remrange ( &awk->parse.locals, nlocals, @@ -668,7 +668,7 @@ static xp_awk_node_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top) /* adjust number of locals for a block without any statements */ if (head == NULL) tmp = 0; - block->type = XP_AWK_NODE_BLOCK; + block->type = XP_AWK_NDE_BLOCK; block->next = XP_NULL; block->body = head; @@ -686,7 +686,7 @@ and merged to top-level block */ block->nlocals = 0; } - return (xp_awk_node_t*)block; + return (xp_awk_nde_t*)block; } static xp_awk_t* __collect_globals (xp_awk_t* awk) @@ -785,35 +785,35 @@ static xp_awk_t* __collect_locals (xp_awk_t* awk, xp_size_t nlocals) return awk; } -static xp_awk_node_t* __parse_statement (xp_awk_t* awk) +static xp_awk_nde_t* __parse_statement (xp_awk_t* awk) { - xp_awk_node_t* node; + xp_awk_nde_t* nde; if (MATCH(awk,TOKEN_SEMICOLON)) { /* null statement */ - node = (xp_awk_node_t*) xp_malloc (xp_sizeof(xp_awk_node_t)); - if (node == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); + nde = (xp_awk_nde_t*) xp_malloc (xp_sizeof(xp_awk_nde_t)); + if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); - node->type = XP_AWK_NODE_NULL; - node->next = XP_NULL; + nde->type = XP_AWK_NDE_NULL; + nde->next = XP_NULL; if (__get_token(awk) == -1) { - xp_free (node); + xp_free (nde); return XP_NULL; } } else if (MATCH(awk,TOKEN_LBRACE)) { if (__get_token(awk) == -1) return XP_NULL; - node = __parse_block (awk, xp_false); + nde = __parse_block (awk, xp_false); } - else node = __parse_statement_nb (awk); + else nde = __parse_statement_nb (awk); - return node; + return nde; } -static xp_awk_node_t* __parse_statement_nb (xp_awk_t* awk) +static xp_awk_nde_t* __parse_statement_nb (xp_awk_t* awk) { - xp_awk_node_t* node; + xp_awk_nde_t* nde; /* * keywords that don't require any terminating semicolon @@ -836,61 +836,61 @@ static xp_awk_node_t* __parse_statement_nb (xp_awk_t* awk) */ if (MATCH(awk,TOKEN_DO)) { if (__get_token(awk) == -1) return XP_NULL; - node = __parse_dowhile (awk); + nde = __parse_dowhile (awk); } else if (MATCH(awk,TOKEN_BREAK)) { if (__get_token(awk) == -1) return XP_NULL; - node = __parse_break(awk); + nde = __parse_break(awk); } else if (MATCH(awk,TOKEN_CONTINUE)) { if (__get_token(awk) == -1) return XP_NULL; - node = __parse_continue(awk); + nde = __parse_continue(awk); } else if (MATCH(awk,TOKEN_RETURN)) { if (__get_token(awk) == -1) return XP_NULL; - node = __parse_return(awk); + nde = __parse_return(awk); } else if (MATCH(awk,TOKEN_EXIT)) { if (__get_token(awk) == -1) return XP_NULL; - node = __parse_exit(awk); + nde = __parse_exit(awk); } /* TODO: else if (MATCH(awk,TOKEN_DELETE)) { if (__get_token(awk) == -1) return XP_NULL; - node = __parse_delete(awk); + nde = __parse_delete(awk); } */ else if (MATCH(awk,TOKEN_NEXT)) { if (__get_token(awk) == -1) return XP_NULL; - node = __parse_next(awk); + nde = __parse_next(awk); } else if (MATCH(awk,TOKEN_NEXTFILE)) { if (__get_token(awk) == -1) return XP_NULL; - node = __parse_nextfile(awk); + nde = __parse_nextfile(awk); } else { - node = __parse_expression(awk); + nde = __parse_expression(awk); } - if (node == XP_NULL) return XP_NULL; + if (nde == XP_NULL) return XP_NULL; /* check if a statement ends with a semicolon */ if (!MATCH(awk,TOKEN_SEMICOLON)) { - if (node != XP_NULL) xp_awk_clrpt (node); + if (nde != XP_NULL) xp_awk_clrpt (nde); PANIC (awk, XP_AWK_ESEMICOLON); } /* eat up the semicolon and read in the next token */ if (__get_token(awk) == -1) { - if (node != XP_NULL) xp_awk_clrpt (node); + if (nde != XP_NULL) xp_awk_clrpt (nde); return XP_NULL; } - return node; + return nde; } -static xp_awk_node_t* __parse_expression (xp_awk_t* awk) +static xp_awk_nde_t* __parse_expression (xp_awk_t* awk) { /* * ::= | @@ -899,25 +899,25 @@ static xp_awk_node_t* __parse_expression (xp_awk_t* awk) * ::= */ - xp_awk_node_t* x, * y; - xp_awk_node_assign_t* node; + xp_awk_nde_t* x, * y; + xp_awk_nde_ass_t* nde; x = __parse_basic_expr (awk); if (x == XP_NULL) return XP_NULL; if (!MATCH(awk,TOKEN_ASSIGN)) return x; xp_assert (x->next == XP_NULL); - if (x->type != XP_AWK_NODE_ARG && - x->type != XP_AWK_NODE_ARGIDX && - x->type != XP_AWK_NODE_NAMED && - x->type != XP_AWK_NODE_NAMEDIDX && - x->type != XP_AWK_NODE_GLOBAL && - x->type != XP_AWK_NODE_GLOBALIDX && - x->type != XP_AWK_NODE_LOCAL && - x->type != XP_AWK_NODE_LOCALIDX && - x->type != XP_AWK_NODE_POS) { + if (x->type != XP_AWK_NDE_ARG && + x->type != XP_AWK_NDE_ARGIDX && + x->type != XP_AWK_NDE_NAMED && + x->type != XP_AWK_NDE_NAMEDIDX && + x->type != XP_AWK_NDE_GLOBAL && + x->type != XP_AWK_NDE_GLOBALIDX && + x->type != XP_AWK_NDE_LOCAL && + x->type != XP_AWK_NDE_LOCALIDX && + x->type != XP_AWK_NDE_POS) { xp_awk_clrpt (x); - PANIC (awk, XP_AWK_EASSIGN); + PANIC (awk, XP_AWK_EASSIGNMENT); } if (__get_token(awk) == -1) { @@ -931,22 +931,22 @@ static xp_awk_node_t* __parse_expression (xp_awk_t* awk) return XP_NULL; } - node = (xp_awk_node_assign_t*)xp_malloc (xp_sizeof(xp_awk_node_assign_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_ass_t*)xp_malloc (xp_sizeof(xp_awk_nde_ass_t)); + if (nde == XP_NULL) { xp_awk_clrpt (x); xp_awk_clrpt (y); PANIC (awk, XP_AWK_ENOMEM); } - node->type = XP_AWK_NODE_ASSIGN; - node->next = XP_NULL; - node->left = x; - node->right = y; + nde->type = XP_AWK_NDE_ASS; + nde->next = XP_NULL; + nde->left = x; + nde->right = y; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } -static xp_awk_node_t* __parse_basic_expr (xp_awk_t* awk) +static xp_awk_nde_t* __parse_basic_expr (xp_awk_t* awk) { /* ::= * ::= [additiveOp ]* @@ -960,10 +960,10 @@ static xp_awk_node_t* __parse_basic_expr (xp_awk_t* awk) return __parse_equality (awk); } -static xp_awk_node_t* __parse_equality (xp_awk_t* awk) +static xp_awk_nde_t* __parse_equality (xp_awk_t* awk) { - xp_awk_node_expr_t* node; - xp_awk_node_t* left, * right; + xp_awk_nde_expr_t* nde; + xp_awk_nde_t* left, * right; int opcode; left = __parse_relational (awk); @@ -987,29 +987,29 @@ static xp_awk_node_t* __parse_equality (xp_awk_t* awk) // TODO: constant folding -> in other parts of the program also... - node = (xp_awk_node_expr_t*)xp_malloc(xp_sizeof(xp_awk_node_expr_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_expr_t*)xp_malloc(xp_sizeof(xp_awk_nde_expr_t)); + if (nde == XP_NULL) { xp_awk_clrpt (right); xp_awk_clrpt (left); PANIC (awk, XP_AWK_ENOMEM); } - node->type = XP_AWK_NODE_BINARY; - node->next = XP_NULL; - node->opcode = opcode; - node->left = left; - node->right = right; + nde->type = XP_AWK_NDE_BINARY; + nde->next = XP_NULL; + nde->opcode = opcode; + nde->left = left; + nde->right = right; - left = (xp_awk_node_t*)node; + left = (xp_awk_nde_t*)nde; } return left; } -static xp_awk_node_t* __parse_relational (xp_awk_t* awk) +static xp_awk_nde_t* __parse_relational (xp_awk_t* awk) { - xp_awk_node_expr_t* node; - xp_awk_node_t* left, * right; + xp_awk_nde_expr_t* nde; + xp_awk_nde_t* left, * right; int opcode; left = __parse_shift (awk); @@ -1035,29 +1035,29 @@ static xp_awk_node_t* __parse_relational (xp_awk_t* awk) // TODO: constant folding -> in other parts of the program also... - node = (xp_awk_node_expr_t*)xp_malloc(xp_sizeof(xp_awk_node_expr_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_expr_t*)xp_malloc(xp_sizeof(xp_awk_nde_expr_t)); + if (nde == XP_NULL) { xp_awk_clrpt (right); xp_awk_clrpt (left); PANIC (awk, XP_AWK_ENOMEM); } - node->type = XP_AWK_NODE_BINARY; - node->next = XP_NULL; - node->opcode = opcode; - node->left = left; - node->right = right; + nde->type = XP_AWK_NDE_BINARY; + nde->next = XP_NULL; + nde->opcode = opcode; + nde->left = left; + nde->right = right; - left = (xp_awk_node_t*)node; + left = (xp_awk_nde_t*)nde; } return left; } -static xp_awk_node_t* __parse_shift (xp_awk_t* awk) +static xp_awk_nde_t* __parse_shift (xp_awk_t* awk) { - xp_awk_node_expr_t* node; - xp_awk_node_t* left, * right; + xp_awk_nde_expr_t* nde; + xp_awk_nde_t* left, * right; int opcode; left = __parse_additive (awk); @@ -1081,29 +1081,29 @@ static xp_awk_node_t* __parse_shift (xp_awk_t* awk) // TODO: constant folding -> in other parts of the program also... - node = (xp_awk_node_expr_t*)xp_malloc(xp_sizeof(xp_awk_node_expr_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_expr_t*)xp_malloc(xp_sizeof(xp_awk_nde_expr_t)); + if (nde == XP_NULL) { xp_awk_clrpt (right); xp_awk_clrpt (left); PANIC (awk, XP_AWK_ENOMEM); } - node->type = XP_AWK_NODE_BINARY; - node->next = XP_NULL; - node->opcode = opcode; - node->left = left; - node->right = right; + nde->type = XP_AWK_NDE_BINARY; + nde->next = XP_NULL; + nde->opcode = opcode; + nde->left = left; + nde->right = right; - left = (xp_awk_node_t*)node; + left = (xp_awk_nde_t*)nde; } return left; } -static xp_awk_node_t* __parse_additive (xp_awk_t* awk) +static xp_awk_nde_t* __parse_additive (xp_awk_t* awk) { - xp_awk_node_expr_t* node; - xp_awk_node_t* left, * right; + xp_awk_nde_expr_t* nde; + xp_awk_nde_t* left, * right; int opcode; left = __parse_multiplicative (awk); @@ -1127,29 +1127,29 @@ static xp_awk_node_t* __parse_additive (xp_awk_t* awk) // TODO: constant folding -> in other parts of the program also... - node = (xp_awk_node_expr_t*)xp_malloc(xp_sizeof(xp_awk_node_expr_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_expr_t*)xp_malloc(xp_sizeof(xp_awk_nde_expr_t)); + if (nde == XP_NULL) { xp_awk_clrpt (right); xp_awk_clrpt (left); PANIC (awk, XP_AWK_ENOMEM); } - node->type = XP_AWK_NODE_BINARY; - node->next = XP_NULL; - node->opcode = opcode; - node->left = left; - node->right = right; + nde->type = XP_AWK_NDE_BINARY; + nde->next = XP_NULL; + nde->opcode = opcode; + nde->left = left; + nde->right = right; - left = (xp_awk_node_t*)node; + left = (xp_awk_nde_t*)nde; } return left; } -static xp_awk_node_t* __parse_multiplicative (xp_awk_t* awk) +static xp_awk_nde_t* __parse_multiplicative (xp_awk_t* awk) { - xp_awk_node_expr_t* node; - xp_awk_node_t* left, * right; + xp_awk_nde_expr_t* nde; + xp_awk_nde_t* left, * right; int opcode; left = __parse_unary (awk); @@ -1174,14 +1174,14 @@ static xp_awk_node_t* __parse_multiplicative (xp_awk_t* awk) /* TODO: enhance constant folding. do it in a better way */ /* TODO: differentiate different types of numbers ... */ - if (left->type == XP_AWK_NODE_NUM && - right->type == XP_AWK_NODE_NUM) { + if (left->type == XP_AWK_NDE_NUM && + right->type == XP_AWK_NDE_NUM) { xp_long_t l, r; - xp_awk_node_term_t* tmp; + xp_awk_nde_term_t* tmp; xp_char_t buf[256]; - l = __str_to_long (((xp_awk_node_term_t*)left)->value); - r = __str_to_long (((xp_awk_node_term_t*)right)->value); + l = __str_to_long (((xp_awk_nde_term_t*)left)->value); + r = __str_to_long (((xp_awk_nde_term_t*)right)->value); xp_awk_clrpt (left); xp_awk_clrpt (right); @@ -1196,10 +1196,10 @@ static xp_awk_node_t* __parse_multiplicative (xp_awk_t* awk) xp_sprintf (buf, xp_countof(buf), XP_TEXT("%lld"), (long long)l); #endif - tmp = (xp_awk_node_term_t*) xp_malloc (xp_sizeof(xp_awk_node_term_t)); + tmp = (xp_awk_nde_term_t*) xp_malloc (xp_sizeof(xp_awk_nde_term_t)); if (tmp == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); - tmp->type = XP_AWK_NODE_NUM; + tmp->type = XP_AWK_NDE_NUM; tmp->next = XP_NULL; tmp->value = xp_strdup (buf); @@ -1208,35 +1208,35 @@ static xp_awk_node_t* __parse_multiplicative (xp_awk_t* awk) PANIC (awk, XP_AWK_ENOMEM); } - left = (xp_awk_node_t*) tmp; + left = (xp_awk_nde_t*) tmp; continue; } - node = (xp_awk_node_expr_t*)xp_malloc(xp_sizeof(xp_awk_node_expr_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_expr_t*)xp_malloc(xp_sizeof(xp_awk_nde_expr_t)); + if (nde == XP_NULL) { xp_awk_clrpt (right); xp_awk_clrpt (left); PANIC (awk, XP_AWK_ENOMEM); } - node->type = XP_AWK_NODE_BINARY; - node->next = XP_NULL; - node->opcode = opcode; - node->left = left; - node->right = right; + nde->type = XP_AWK_NDE_BINARY; + nde->next = XP_NULL; + nde->opcode = opcode; + nde->left = left; + nde->right = right; - left = (xp_awk_node_t*)node; + left = (xp_awk_nde_t*)nde; } return left; } -static xp_awk_node_t* __parse_unary (xp_awk_t* awk) +static xp_awk_nde_t* __parse_unary (xp_awk_t* awk) { return __parse_primary (awk); } -static xp_awk_node_t* __parse_primary (xp_awk_t* awk) +static xp_awk_nde_t* __parse_primary (xp_awk_t* awk) { if (MATCH(awk,TOKEN_IDENT)) { xp_char_t* name_dup; @@ -1250,25 +1250,25 @@ static xp_awk_node_t* __parse_primary (xp_awk_t* awk) } if (MATCH(awk,TOKEN_LBRACK)) { - xp_awk_node_t* node; - node = __parse_hashidx (awk, name_dup); - if (node == XP_NULL) xp_free (name_dup); - return (xp_awk_node_t*)node; + xp_awk_nde_t* nde; + nde = __parse_hashidx (awk, name_dup); + if (nde == XP_NULL) xp_free (name_dup); + return (xp_awk_nde_t*)nde; } else if (MATCH(awk,TOKEN_LPAREN)) { /* function call */ - xp_awk_node_t* node; - node = __parse_funcall (awk, name_dup); - if (node == XP_NULL) xp_free (name_dup); - return (xp_awk_node_t*)node; + xp_awk_nde_t* nde; + nde = __parse_funcall (awk, name_dup); + if (nde == XP_NULL) xp_free (name_dup); + return (xp_awk_nde_t*)nde; } else { /* normal variable */ - xp_awk_node_var_t* node; + xp_awk_nde_var_t* nde; xp_size_t idxa; - node = (xp_awk_node_var_t*)xp_malloc(xp_sizeof(xp_awk_node_var_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_var_t*)xp_malloc(xp_sizeof(xp_awk_nde_var_t)); + if (nde == XP_NULL) { xp_free (name_dup); PANIC (awk, XP_AWK_ENOMEM); } @@ -1276,151 +1276,151 @@ static xp_awk_node_t* __parse_primary (xp_awk_t* awk) /* search the parameter name list */ idxa = xp_awk_tab_find(&awk->parse.params, name_dup, 0); if (idxa != (xp_size_t)-1) { - node->type = XP_AWK_NODE_ARG; - node->next = XP_NULL; - //node->id.name = XP_NULL; - node->id.name = name_dup; - node->id.idxa = idxa; + nde->type = XP_AWK_NDE_ARG; + nde->next = XP_NULL; + //nde->id.name = XP_NULL; + nde->id.name = name_dup; + nde->id.idxa = idxa; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } /* search the local variable list */ idxa = xp_awk_tab_rrfind(&awk->parse.locals, name_dup, 0); if (idxa != (xp_size_t)-1) { - node->type = XP_AWK_NODE_LOCAL; - node->next = XP_NULL; - //node->id.name = XP_NULL; - node->id.name = name_dup; - node->id.idxa = idxa; + nde->type = XP_AWK_NDE_LOCAL; + nde->next = XP_NULL; + //nde->id.name = XP_NULL; + nde->id.name = name_dup; + nde->id.idxa = idxa; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } /* search the global variable list */ idxa = xp_awk_tab_rrfind(&awk->parse.globals, name_dup, 0); if (idxa != (xp_size_t)-1) { - node->type = XP_AWK_NODE_GLOBAL; - node->next = XP_NULL; - //node->id.name = XP_NULL; - node->id.name = name_dup; - node->id.idxa = idxa; + nde->type = XP_AWK_NDE_GLOBAL; + nde->next = XP_NULL; + //nde->id.name = XP_NULL; + nde->id.name = name_dup; + nde->id.idxa = idxa; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } if (awk->opt.parse & XP_AWK_IMPLICIT) { - node->type = XP_AWK_NODE_NAMED; - node->next = XP_NULL; - node->id.name = name_dup; - node->id.idxa = (xp_size_t)-1; + nde->type = XP_AWK_NDE_NAMED; + nde->next = XP_NULL; + nde->id.name = name_dup; + nde->id.idxa = (xp_size_t)-1; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } /* undefined variable */ xp_free (name_dup); - xp_free (node); + xp_free (nde); PANIC (awk, XP_AWK_EUNDEF); } } else if (MATCH(awk,TOKEN_INTEGER)) { - xp_awk_node_term_t* node; + xp_awk_nde_term_t* nde; - node = (xp_awk_node_term_t*)xp_malloc(xp_sizeof(xp_awk_node_term_t)); - if (node == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); + nde = (xp_awk_nde_term_t*)xp_malloc(xp_sizeof(xp_awk_nde_term_t)); + if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); - node->type = XP_AWK_NODE_NUM; - node->next = XP_NULL; - node->value = xp_strdup(XP_STR_BUF(&awk->token.name)); - if (node->value == XP_NULL) { - xp_free (node); + nde->type = XP_AWK_NDE_NUM; + nde->next = XP_NULL; + nde->value = xp_strdup(XP_STR_BUF(&awk->token.name)); + if (nde->value == XP_NULL) { + xp_free (nde); PANIC (awk, XP_AWK_ENOMEM); } if (__get_token(awk) == -1) { - xp_free (node->value); - xp_free (node); + xp_free (nde->value); + xp_free (nde); return XP_NULL; } - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } else if (MATCH(awk,TOKEN_STRING)) { - xp_awk_node_term_t* node; + xp_awk_nde_term_t* nde; - node = (xp_awk_node_term_t*)xp_malloc(xp_sizeof(xp_awk_node_term_t)); - if (node == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); + nde = (xp_awk_nde_term_t*)xp_malloc(xp_sizeof(xp_awk_nde_term_t)); + if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); - node->type = XP_AWK_NODE_STR; - node->next = XP_NULL; - node->value = xp_strdup(XP_STR_BUF(&awk->token.name)); - if (node->value == XP_NULL) { - xp_free (node); + nde->type = XP_AWK_NDE_STR; + nde->next = XP_NULL; + nde->value = xp_strdup(XP_STR_BUF(&awk->token.name)); + if (nde->value == XP_NULL) { + xp_free (nde); PANIC (awk, XP_AWK_ENOMEM); } if (__get_token(awk) == -1) { - xp_free (node->value); - xp_free (node); + xp_free (nde->value); + xp_free (nde); return XP_NULL; } - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } else if (MATCH(awk,TOKEN_DOLLAR)) { - xp_awk_node_sgv_t* node; - xp_awk_node_t* prim; + xp_awk_nde_sgv_t* nde; + xp_awk_nde_t* prim; if (__get_token(awk)) return XP_NULL; prim = __parse_primary (awk); if (prim == XP_NULL) return XP_NULL; - node = (xp_awk_node_sgv_t*) xp_malloc (xp_sizeof(xp_awk_node_sgv_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_sgv_t*) xp_malloc (xp_sizeof(xp_awk_nde_sgv_t)); + if (nde == XP_NULL) { xp_awk_clrpt (prim); PANIC (awk, XP_AWK_ENOMEM); } - node->type = XP_AWK_NODE_POS; - node->next = XP_NULL; - node->value = prim; + nde->type = XP_AWK_NDE_POS; + nde->next = XP_NULL; + nde->value = prim; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } else if (MATCH(awk,TOKEN_LPAREN)) { - xp_awk_node_t* node; + xp_awk_nde_t* nde; /* eat up the left parenthesis */ if (__get_token(awk) == -1) return XP_NULL; /* parse the sub-expression inside the parentheses */ - node = __parse_expression (awk); - if (node == XP_NULL) return XP_NULL; + nde = __parse_expression (awk); + if (nde == XP_NULL) return XP_NULL; /* check for the closing parenthesis */ if (!MATCH(awk,TOKEN_RPAREN)) { - xp_awk_clrpt (node); + xp_awk_clrpt (nde); PANIC (awk, XP_AWK_ERPAREN); } if (__get_token(awk) == -1) { - xp_awk_clrpt (node); + xp_awk_clrpt (nde); return XP_NULL; } - return node; + return nde; } /* valid expression introducer is expected */ PANIC (awk, XP_AWK_EEXPR); } -static xp_awk_node_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name) +static xp_awk_nde_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name) { - xp_awk_node_t* idx; - xp_awk_node_idx_t* node; + xp_awk_nde_t* idx; + xp_awk_nde_idx_t* nde; xp_size_t idxa; if (__get_token(awk) == -1) return XP_NULL; @@ -1438,8 +1438,8 @@ static xp_awk_node_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name) return XP_NULL; } - node = (xp_awk_node_idx_t*) xp_malloc (xp_sizeof(xp_awk_node_idx_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_idx_t*) xp_malloc (xp_sizeof(xp_awk_nde_idx_t)); + if (nde == XP_NULL) { xp_awk_clrpt (idx); PANIC (awk, XP_AWK_ENOMEM); } @@ -1447,61 +1447,61 @@ static xp_awk_node_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name) /* search the parameter name list */ idxa = xp_awk_tab_find(&awk->parse.params, name, 0); if (idxa != (xp_size_t)-1) { - node->type = XP_AWK_NODE_ARGIDX; - node->next = XP_NULL; - //node->id.name = XP_NULL; - node->id.name = name; - node->id.idxa = idxa; - node->idx = idx; + nde->type = XP_AWK_NDE_ARGIDX; + nde->next = XP_NULL; + //nde->id.name = XP_NULL; + nde->id.name = name; + nde->id.idxa = idxa; + nde->idx = idx; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } /* search the local variable list */ idxa = xp_awk_tab_rrfind(&awk->parse.locals, name, 0); if (idxa != (xp_size_t)-1) { - node->type = XP_AWK_NODE_LOCALIDX; - node->next = XP_NULL; - //node->id.name = XP_NULL; - node->id.name = name; - node->id.idxa = idxa; - node->idx = idx; + nde->type = XP_AWK_NDE_LOCALIDX; + nde->next = XP_NULL; + //nde->id.name = XP_NULL; + nde->id.name = name; + nde->id.idxa = idxa; + nde->idx = idx; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } /* search the global variable list */ idxa = xp_awk_tab_rrfind(&awk->parse.globals, name, 0); if (idxa != (xp_size_t)-1) { - node->type = XP_AWK_NODE_GLOBALIDX; - node->next = XP_NULL; - //node->id.name = XP_NULL; - node->id.name = name; - node->id.idxa = idxa; + nde->type = XP_AWK_NDE_GLOBALIDX; + nde->next = XP_NULL; + //nde->id.name = XP_NULL; + nde->id.name = name; + nde->id.idxa = idxa; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } if (awk->opt.parse & XP_AWK_IMPLICIT) { - node->type = XP_AWK_NODE_NAMEDIDX; - node->next = XP_NULL; - node->id.name = name; - node->id.idxa = (xp_size_t)-1; - node->idx = idx; + nde->type = XP_AWK_NDE_NAMEDIDX; + nde->next = XP_NULL; + nde->id.name = name; + nde->id.idxa = (xp_size_t)-1; + nde->idx = idx; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } /* undefined variable */ xp_awk_clrpt (idx); - xp_free (node); + xp_free (nde); PANIC (awk, XP_AWK_EUNDEF); } -static xp_awk_node_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name) +static xp_awk_nde_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name) { - xp_awk_node_t* head, * curr, * node; - xp_awk_node_call_t* call; + xp_awk_nde_t* head, * curr, * nde; + xp_awk_nde_call_t* call; if (__get_token(awk) == -1) return XP_NULL; @@ -1513,15 +1513,15 @@ static xp_awk_node_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name) } else { while (1) { - node = __parse_expression (awk); - if (node == XP_NULL) { + nde = __parse_expression (awk); + if (nde == XP_NULL) { if (head != XP_NULL) xp_awk_clrpt (head); return XP_NULL; } - if (head == XP_NULL) head = node; - else curr->next = node; - curr = node; + if (head == XP_NULL) head = nde; + else curr->next = nde; + curr = nde; if (MATCH(awk,TOKEN_RPAREN)) { if (__get_token(awk) == -1) { @@ -1544,26 +1544,26 @@ static xp_awk_node_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name) } - call = (xp_awk_node_call_t*)xp_malloc (xp_sizeof(xp_awk_node_call_t)); + call = (xp_awk_nde_call_t*)xp_malloc (xp_sizeof(xp_awk_nde_call_t)); if (call == XP_NULL) { if (head != XP_NULL) xp_awk_clrpt (head); PANIC (awk, XP_AWK_ENOMEM); } - call->type = XP_AWK_NODE_CALL; + call->type = XP_AWK_NDE_CALL; call->next = XP_NULL; call->name = name; call->args = head; - return (xp_awk_node_t*)call; + return (xp_awk_nde_t*)call; } -static xp_awk_node_t* __parse_if (xp_awk_t* awk) +static xp_awk_nde_t* __parse_if (xp_awk_t* awk) { - xp_awk_node_t* test; - xp_awk_node_t* then_part; - xp_awk_node_t* else_part; - xp_awk_node_if_t* node; + xp_awk_nde_t* test; + xp_awk_nde_t* then_part; + xp_awk_nde_t* else_part; + xp_awk_nde_if_t* nde; if (!MATCH(awk,TOKEN_LPAREN)) PANIC (awk, XP_AWK_ELPAREN); if (__get_token(awk) == -1) return XP_NULL; @@ -1603,27 +1603,27 @@ static xp_awk_node_t* __parse_if (xp_awk_t* awk) } else else_part = XP_NULL; - node = (xp_awk_node_if_t*) xp_malloc (xp_sizeof(xp_awk_node_if_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_if_t*) xp_malloc (xp_sizeof(xp_awk_nde_if_t)); + if (nde == XP_NULL) { xp_awk_clrpt (else_part); xp_awk_clrpt (then_part); xp_awk_clrpt (test); PANIC (awk, XP_AWK_ENOMEM); } - node->type = XP_AWK_NODE_IF; - node->next = XP_NULL; - node->test = test; - node->then_part = then_part; - node->else_part = else_part; + nde->type = XP_AWK_NDE_IF; + nde->next = XP_NULL; + nde->test = test; + nde->then_part = then_part; + nde->else_part = else_part; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } -static xp_awk_node_t* __parse_while (xp_awk_t* awk) +static xp_awk_nde_t* __parse_while (xp_awk_t* awk) { - xp_awk_node_t* test, * body; - xp_awk_node_while_t* node; + xp_awk_nde_t* test, * body; + xp_awk_nde_while_t* nde; if (!MATCH(awk,TOKEN_LPAREN)) PANIC (awk, XP_AWK_ELPAREN); if (__get_token(awk) == -1) return XP_NULL; @@ -1647,25 +1647,25 @@ static xp_awk_node_t* __parse_while (xp_awk_t* awk) return XP_NULL; } - node = (xp_awk_node_while_t*) xp_malloc (xp_sizeof(xp_awk_node_while_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_while_t*) xp_malloc (xp_sizeof(xp_awk_nde_while_t)); + if (nde == XP_NULL) { xp_awk_clrpt (body); xp_awk_clrpt (test); PANIC (awk, XP_AWK_ENOMEM); } - node->type = XP_AWK_NODE_WHILE; - node->next = XP_NULL; - node->test = test; - node->body = body; + nde->type = XP_AWK_NDE_WHILE; + nde->next = XP_NULL; + nde->test = test; + nde->body = body; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } -static xp_awk_node_t* __parse_for (xp_awk_t* awk) +static xp_awk_nde_t* __parse_for (xp_awk_t* awk) { - xp_awk_node_t* init, * test, * incr, * body; - xp_awk_node_for_t* node; + xp_awk_nde_t* init, * test, * incr, * body; + xp_awk_nde_for_t* nde; // TODO: parse for (x in list) ... @@ -1741,8 +1741,8 @@ static xp_awk_node_t* __parse_for (xp_awk_t* awk) return XP_NULL; } - node = (xp_awk_node_for_t*) xp_malloc (xp_sizeof(xp_awk_node_for_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_for_t*) xp_malloc (xp_sizeof(xp_awk_nde_for_t)); + if (nde == XP_NULL) { xp_awk_clrpt (init); xp_awk_clrpt (test); xp_awk_clrpt (incr); @@ -1750,20 +1750,20 @@ static xp_awk_node_t* __parse_for (xp_awk_t* awk) PANIC (awk, XP_AWK_ENOMEM); } - node->type = XP_AWK_NODE_FOR; - node->next = XP_NULL; - node->init = init; - node->test = test; - node->incr = incr; - node->body = body; + nde->type = XP_AWK_NDE_FOR; + nde->next = XP_NULL; + nde->init = init; + nde->test = test; + nde->incr = incr; + nde->body = body; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } -static xp_awk_node_t* __parse_dowhile (xp_awk_t* awk) +static xp_awk_nde_t* __parse_dowhile (xp_awk_t* awk) { - xp_awk_node_t* test, * body; - xp_awk_node_while_t* node; + xp_awk_nde_t* test, * body; + xp_awk_nde_while_t* nde; body = __parse_statement (awk); if (body == XP_NULL) return XP_NULL; @@ -1806,54 +1806,54 @@ static xp_awk_node_t* __parse_dowhile (xp_awk_t* awk) return XP_NULL; } - node = (xp_awk_node_while_t*) xp_malloc (xp_sizeof(xp_awk_node_while_t)); - if (node == XP_NULL) { + nde = (xp_awk_nde_while_t*) xp_malloc (xp_sizeof(xp_awk_nde_while_t)); + if (nde == XP_NULL) { xp_awk_clrpt (body); xp_awk_clrpt (test); PANIC (awk, XP_AWK_ENOMEM); } - node->type = XP_AWK_NODE_DOWHILE; - node->next = XP_NULL; - node->test = test; - node->body = body; + nde->type = XP_AWK_NDE_DOWHILE; + nde->next = XP_NULL; + nde->test = test; + nde->body = body; - return (xp_awk_node_t*)node; + return (xp_awk_nde_t*)nde; } -static xp_awk_node_t* __parse_break (xp_awk_t* awk) +static xp_awk_nde_t* __parse_break (xp_awk_t* awk) { - xp_awk_node_t* node; + xp_awk_nde_t* nde; - node = (xp_awk_node_t*) xp_malloc (xp_sizeof(xp_awk_node_t)); - if (node == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); - node->type = XP_AWK_NODE_BREAK; - node->next = XP_NULL; + nde = (xp_awk_nde_t*) xp_malloc (xp_sizeof(xp_awk_nde_t)); + if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); + nde->type = XP_AWK_NDE_BREAK; + nde->next = XP_NULL; - return node; + return nde; } -static xp_awk_node_t* __parse_continue (xp_awk_t* awk) +static xp_awk_nde_t* __parse_continue (xp_awk_t* awk) { - xp_awk_node_t* node; + xp_awk_nde_t* nde; - node = (xp_awk_node_t*) xp_malloc (xp_sizeof(xp_awk_node_t)); - if (node == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); - node->type = XP_AWK_NODE_CONTINUE; - node->next = XP_NULL; + nde = (xp_awk_nde_t*) xp_malloc (xp_sizeof(xp_awk_nde_t)); + if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); + nde->type = XP_AWK_NDE_CONTINUE; + nde->next = XP_NULL; - return node; + return nde; } -static xp_awk_node_t* __parse_return (xp_awk_t* awk) +static xp_awk_nde_t* __parse_return (xp_awk_t* awk) { - xp_awk_node_sgv_t* node; - xp_awk_node_t* val; + xp_awk_nde_sgv_t* nde; + xp_awk_nde_t* val; - node = (xp_awk_node_sgv_t*) xp_malloc (xp_sizeof(xp_awk_node_sgv_t)); - if (node == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); - node->type = XP_AWK_NODE_RETURN; - node->next = XP_NULL; + nde = (xp_awk_nde_sgv_t*) xp_malloc (xp_sizeof(xp_awk_nde_sgv_t)); + if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); + nde->type = XP_AWK_NDE_RETURN; + nde->next = XP_NULL; if (MATCH(awk,TOKEN_SEMICOLON)) { /* no return value */ @@ -1863,24 +1863,24 @@ static xp_awk_node_t* __parse_return (xp_awk_t* awk) val = __parse_expression (awk); if (val == XP_NULL) { - xp_free (node); + xp_free (nde); return XP_NULL; } } - node->value = val; - return (xp_awk_node_t*)node; + nde->value = val; + return (xp_awk_nde_t*)nde; } -static xp_awk_node_t* __parse_exit (xp_awk_t* awk) +static xp_awk_nde_t* __parse_exit (xp_awk_t* awk) { - xp_awk_node_sgv_t* node; - xp_awk_node_t* val; + xp_awk_nde_sgv_t* nde; + xp_awk_nde_t* val; - node = (xp_awk_node_sgv_t*) xp_malloc (xp_sizeof(xp_awk_node_sgv_t)); - if (node == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); - node->type = XP_AWK_NODE_EXIT; - node->next = XP_NULL; + nde = (xp_awk_nde_sgv_t*) xp_malloc (xp_sizeof(xp_awk_nde_sgv_t)); + if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); + nde->type = XP_AWK_NDE_EXIT; + nde->next = XP_NULL; if (MATCH(awk,TOKEN_SEMICOLON)) { /* no exit code */ @@ -1889,37 +1889,37 @@ static xp_awk_node_t* __parse_exit (xp_awk_t* awk) else { val = __parse_expression (awk); if (val == XP_NULL) { - xp_free (node); + xp_free (nde); return XP_NULL; } } - node->value = val; - return (xp_awk_node_t*)node; + nde->value = val; + return (xp_awk_nde_t*)nde; } -static xp_awk_node_t* __parse_next (xp_awk_t* awk) +static xp_awk_nde_t* __parse_next (xp_awk_t* awk) { - xp_awk_node_t* node; + xp_awk_nde_t* nde; - node = (xp_awk_node_t*) xp_malloc (xp_sizeof(xp_awk_node_t)); - if (node == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); - node->type = XP_AWK_NODE_NEXT; - node->next = XP_NULL; + nde = (xp_awk_nde_t*) xp_malloc (xp_sizeof(xp_awk_nde_t)); + if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); + nde->type = XP_AWK_NDE_NEXT; + nde->next = XP_NULL; - return node; + return nde; } -static xp_awk_node_t* __parse_nextfile (xp_awk_t* awk) +static xp_awk_nde_t* __parse_nextfile (xp_awk_t* awk) { - xp_awk_node_t* node; + xp_awk_nde_t* nde; - node = (xp_awk_node_t*) xp_malloc (xp_sizeof(xp_awk_node_t)); - if (node == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); - node->type = XP_AWK_NODE_NEXTFILE; - node->next = XP_NULL; + nde = (xp_awk_nde_t*) xp_malloc (xp_sizeof(xp_awk_nde_t)); + if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); + nde->type = XP_AWK_NDE_NEXTFILE; + nde->next = XP_NULL; - return node; + return nde; } static int __get_token (xp_awk_t* awk) diff --git a/ase/awk/run.c b/ase/awk/run.c index 82948476..ad255066 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.4 2006-03-02 15:36:30 bacon Exp $ + * $Id: run.c,v 1.5 2006-03-03 11:45:45 bacon Exp $ */ #include @@ -8,127 +8,153 @@ #include #endif -static int __run_block (xp_awk_t* awk, xp_awk_node_t* node); -static int __run_statement (xp_awk_t* awk, xp_awk_node_t* node); -static int __run_assignment (xp_awk_t* awk, xp_awk_node_assign_t* node); -static int __eval_expr (xp_awk_t* awk, xp_awk_node_t* node); +static int __run_block (xp_awk_t* awk, xp_awk_nde_t* nde); +static int __run_statement (xp_awk_t* awk, xp_awk_nde_t* nde); +static int __run_assignment (xp_awk_t* awk, xp_awk_nde_ass_t* nde); + +static xp_awk_val_t* __eval_expr (xp_awk_t* awk, xp_awk_nde_t* nde); int xp_awk_run (xp_awk_t* awk) { - if (awk->tree.begin != XP_NULL) { + if (awk->tree.begin != XP_NULL) + { if (__run_block(awk, awk->tree.begin) == -1) return -1; } - if (awk->tree.end != XP_NULL) { + if (awk->tree.end != XP_NULL) + { if (__run_block(awk, awk->tree.end) == -1) return -1; } return 0; } -static int __run_block (xp_awk_t* awk, xp_awk_node_t* node) +static int __run_block (xp_awk_t* awk, xp_awk_nde_t* nde) { - xp_assert (node->type == XP_AWK_NODE_BLOCK); + xp_awk_nde_t* p; -/* - xp_awk_node_t* p = node; + xp_assert (nde->type == XP_AWK_NDE_BLOCK); - while (p != XP_NULL) { + p = nde; - if (__run_statement (awk, p) == -1) return -1; + while (p != XP_NULL) + { + if (__run_statement(awk, p) == -1) return -1; p = p->next; } -*/ return 0; } -static int __run_statement (xp_awk_t* awk, xp_awk_node_t* node) +static int __run_statement (xp_awk_t* awk, xp_awk_nde_t* nde) { -#if 0 - switch (node->type) { - case XP_AWK_NODE_NULL: + switch (nde->type) + { + case XP_AWK_NDE_NULL: /* do nothing */ break; - case XP_AWK_NODE_BLOCK: - if (__run_block(awk, node) == -1) return -1; + case XP_AWK_NDE_BLOCK: + if (__run_block(awk, nde) == -1) return -1; break; - case XP_AWK_NODE_IF: +#if 0 + case XP_AWK_NDE_IF: break; - case XP_AWK_NODE_WHILE: + case XP_AWK_NDE_WHILE: break; - case XP_AWK_NODE_DOWHILE: + case XP_AWK_NDE_DOWHILE: break; - case XP_AWK_NODE_FOR: + case XP_AWK_NDE_FOR: break; - case XP_AWK_NODE_BREAK: + case XP_AWK_NDE_BREAK: break; - case XP_AWK_NODE_CONTINUE: + case XP_AWK_NDE_CONTINUE: break; - case XP_AWK_NODE_RETURN: + case XP_AWK_NDE_RETURN: break; - case XP_AWK_NODE_EXIT: + case XP_AWK_NDE_EXIT: break; - case XP_AWK_NODE_NEXT: + case XP_AWK_NDE_NEXT: break; - case XP_AWK_NODE_NEXTFILE: + case XP_AWK_NDE_NEXTFILE: + break; +#endif + + case XP_AWK_NDE_ASS: + if (__run_assignment ( + awk, (xp_awk_nde_ass_t*)nde) == -1) return -1; break; - case XP_AWK_NODE_ASSIGN: - if (__run_assignment (awk, node) == -1) return -1; +#if 0 + case XP_AWK_NDE_NUM: break; +#endif - case XP_AWK_NODE_NUM: - break; + default: + /* this should never be reached */ + // TODO: set errnum .... + return -1; } return 0; } -static int __run_assignment (xp_awk_t* awk, xp_awk_node_assign_t* node) +static int __run_assignment (xp_awk_t* awk, xp_awk_nde_ass_t* nde) { - if (node->type == XP_AWK_NODE_NAMED) { - xp_awk_node_t* right = __eval_expr (awk, node->right); - if (right == NULL) return -1; + if (nde->type == XP_AWK_NDE_NAMED) + { + xp_awk_nde_var_t* left = (xp_awk_nde_var_t*)nde->left; + xp_awk_val_t* right = __eval_expr (awk, nde->right); - if (xp_awk_map_insert(awk->run.named, right) == -1) { + xp_assert (left != XP_NULL); + if (right == XP_NULL) return -1; + + if (xp_awk_map_put ( + &awk->run.named, left->id.name, right) == XP_NULL) + { awk->errnum = XP_AWK_ENOMEM; return -1; } } - else if (node->type == XP_AWK_NODE_GLOBAL) { + else if (nde->type == XP_AWK_NDE_GLOBAL) + { } - else if (node->type == XP_AWK_NODE_LOCAL) { + else if (nde->type == XP_AWK_NDE_LOCAL) + { } - else if (node->type == XP_AWK_NODE_ARG) { + else if (nde->type == XP_AWK_NDE_ARG) + { } - else if (node->type == XP_AWK_NODE_NAMEIDX) { + else if (nde->type == XP_AWK_NDE_NAMEDIDX) + { } - else if (node->type == XP_AWK_NODE_GLOBALIDX) { + else if (nde->type == XP_AWK_NDE_GLOBALIDX) + { } - else if (node->type == XP_AWK_NODE_LOCALIDX) { + else if (nde->type == XP_AWK_NDE_LOCALIDX) + { } - else if (node->type == XP_AWK_NODE_ARGIDX) { + else if (nde->type == XP_AWK_NDE_ARGIDX) + { } - - esle { - awk->errnum = XP_AWK_EINTERNAL; + else + { + /* this should never be reached */ + // TODO: set errnum .... return -1; } -#endif return 0; } -static int __eval_expr (xp_awk_t* awk, xp_awk_node_t* node) +static xp_awk_val_t* __eval_expr (xp_awk_t* awk, xp_awk_nde_t* nde) { - return -1; + return XP_NULL; } diff --git a/ase/awk/sa.h b/ase/awk/sa.h index dbec49df..b84e2080 100644 --- a/ase/awk/sa.h +++ b/ase/awk/sa.h @@ -1,5 +1,5 @@ /* - * $Id: sa.h,v 1.10 2006-02-18 16:14:14 bacon Exp $ + * $Id: sa.h,v 1.11 2006-03-03 11:45:45 bacon Exp $ */ #ifndef _XP_AWK_SA_H_ @@ -67,10 +67,13 @@ typedef ssize_t xp_ssize_t; #if defined(_WIN32) typedef __int64 xp_long_t; +typedef long double xp_real_t; #elif defined(vax) || defined(__vax) typedef long xp_long_t; +typedef long double xp_real_t; #else typedef long long xp_long_t; +typedef long double xp_real_t; #endif #define XP_STR_LEN(x) ((x)->size) diff --git a/ase/awk/tree.c b/ase/awk/tree.c index a55762f8..c345e5b6 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c,v 1.20 2006-02-08 16:14:31 bacon Exp $ + * $Id: tree.c,v 1.21 2006-03-03 11:45:45 bacon Exp $ */ #include @@ -28,9 +28,9 @@ static const xp_char_t* __binop_str[] = }; static void __print_tabs (int depth); -static int __print_expr_node (xp_awk_node_t* node); -static int __print_expr_node_list (xp_awk_node_t* tree); -static void __print_statements (xp_awk_node_t* tree, int depth); +static int __print_expr_nde (xp_awk_nde_t* nde); +static int __print_expr_nde_list (xp_awk_nde_t* tree); +static void __print_statements (xp_awk_nde_t* tree, int depth); static void __print_tabs (int depth) { @@ -38,119 +38,119 @@ static void __print_tabs (int depth) for (i = 0; i < depth; i++) xp_printf (XP_TEXT("\t")); } -static int __print_expr_node (xp_awk_node_t* node) +static int __print_expr_nde (xp_awk_nde_t* nde) { - switch (node->type) { - case XP_AWK_NODE_ASSIGN: - if (__print_expr_node (((xp_awk_node_assign_t*)node)->left) == -1) return -1; + switch (nde->type) { + case XP_AWK_NDE_ASS: + if (__print_expr_nde (((xp_awk_nde_ass_t*)nde)->left) == -1) return -1; xp_printf (XP_TEXT(" = ")); - if (__print_expr_node (((xp_awk_node_assign_t*)node)->right) == -1) return -1; - xp_assert ((((xp_awk_node_assign_t*)node)->right)->next == XP_NULL); + if (__print_expr_nde (((xp_awk_nde_ass_t*)nde)->right) == -1) return -1; + xp_assert ((((xp_awk_nde_ass_t*)nde)->right)->next == XP_NULL); break; - case XP_AWK_NODE_BINARY: + case XP_AWK_NDE_BINARY: xp_printf (XP_TEXT("(")); - if (__print_expr_node (((xp_awk_node_expr_t*)node)->left) == -1) return -1; - xp_assert ((((xp_awk_node_expr_t*)node)->left)->next == XP_NULL); - xp_printf (XP_TEXT(" %s "), __binop_str[((xp_awk_node_expr_t*)node)->opcode]); - if (((xp_awk_node_expr_t*)node)->right->type == XP_AWK_NODE_ASSIGN) xp_printf (XP_TEXT("(")); - if (__print_expr_node (((xp_awk_node_expr_t*)node)->right) == -1) return -1; - if (((xp_awk_node_expr_t*)node)->right->type == XP_AWK_NODE_ASSIGN) xp_printf (XP_TEXT(")")); - xp_assert ((((xp_awk_node_expr_t*)node)->right)->next == XP_NULL); + if (__print_expr_nde (((xp_awk_nde_expr_t*)nde)->left) == -1) return -1; + xp_assert ((((xp_awk_nde_expr_t*)nde)->left)->next == XP_NULL); + xp_printf (XP_TEXT(" %s "), __binop_str[((xp_awk_nde_expr_t*)nde)->opcode]); + if (((xp_awk_nde_expr_t*)nde)->right->type == XP_AWK_NDE_ASS) xp_printf (XP_TEXT("(")); + if (__print_expr_nde (((xp_awk_nde_expr_t*)nde)->right) == -1) return -1; + if (((xp_awk_nde_expr_t*)nde)->right->type == XP_AWK_NDE_ASS) xp_printf (XP_TEXT(")")); + xp_assert ((((xp_awk_nde_expr_t*)nde)->right)->next == XP_NULL); xp_printf (XP_TEXT(")")); break; - case XP_AWK_NODE_UNARY: + case XP_AWK_NDE_UNARY: // TODO: xp_printf (XP_TEXT("unary basic expression\n")); break; - case XP_AWK_NODE_STR: - xp_printf (XP_TEXT("\"%s\""), ((xp_awk_node_term_t*)node)->value); + case XP_AWK_NDE_STR: + xp_printf (XP_TEXT("\"%s\""), ((xp_awk_nde_term_t*)nde)->value); break; - case XP_AWK_NODE_NUM: - xp_printf (XP_TEXT("%s"), ((xp_awk_node_term_t*)node)->value); + case XP_AWK_NDE_NUM: + xp_printf (XP_TEXT("%s"), ((xp_awk_nde_term_t*)nde)->value); break; - case XP_AWK_NODE_ARG: - xp_assert (((xp_awk_node_var_t*)node)->id.idxa != (xp_size_t)-1); + case XP_AWK_NDE_ARG: + xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1); xp_printf (XP_TEXT("__arg%lu"), - (unsigned long)((xp_awk_node_var_t*)node)->id.idxa); + (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa); break; - case XP_AWK_NODE_ARGIDX: - xp_assert (((xp_awk_node_var_t*)node)->id.idxa != (xp_size_t)-1); + case XP_AWK_NDE_ARGIDX: + xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1); xp_printf (XP_TEXT("__arg%lu["), - (unsigned long)((xp_awk_node_idx_t*)node)->id.idxa); - __print_expr_node (((xp_awk_node_idx_t*)node)->idx); + (unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa); + __print_expr_nde (((xp_awk_nde_idx_t*)nde)->idx); xp_printf (XP_TEXT("]")); break; - case XP_AWK_NODE_NAMED: - xp_assert (((xp_awk_node_var_t*)node)->id.idxa == (xp_size_t)-1); - xp_printf (XP_TEXT("%s"), ((xp_awk_node_var_t*)node)->id.name); + case XP_AWK_NDE_NAMED: + xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa == (xp_size_t)-1); + xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name); break; - case XP_AWK_NODE_NAMEDIDX: - xp_assert (((xp_awk_node_idx_t*)node)->id.idxa == (xp_size_t)-1); - xp_printf (XP_TEXT("%s["), ((xp_awk_node_idx_t*)node)->id.name); - __print_expr_node (((xp_awk_node_idx_t*)node)->idx); + case XP_AWK_NDE_NAMEDIDX: + xp_assert (((xp_awk_nde_idx_t*)nde)->id.idxa == (xp_size_t)-1); + xp_printf (XP_TEXT("%s["), ((xp_awk_nde_idx_t*)nde)->id.name); + __print_expr_nde (((xp_awk_nde_idx_t*)nde)->idx); xp_printf (XP_TEXT("]")); break; - case XP_AWK_NODE_GLOBAL: - if (((xp_awk_node_var_t*)node)->id.idxa != (xp_size_t)-1) { + case XP_AWK_NDE_GLOBAL: + if (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1) { xp_printf (XP_TEXT("__global%lu"), - (unsigned long)((xp_awk_node_var_t*)node)->id.idxa); + (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa); } else { - xp_printf (XP_TEXT("%s"), ((xp_awk_node_var_t*)node)->id.name); + xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name); } break; - case XP_AWK_NODE_GLOBALIDX: - if (((xp_awk_node_idx_t*)node)->id.idxa != (xp_size_t)-1) { + case XP_AWK_NDE_GLOBALIDX: + if (((xp_awk_nde_idx_t*)nde)->id.idxa != (xp_size_t)-1) { xp_printf (XP_TEXT("__global%lu["), - (unsigned long)((xp_awk_node_idx_t*)node)->id.idxa); + (unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa); } else { - xp_printf (XP_TEXT("%s["), ((xp_awk_node_idx_t*)node)->id.name); + xp_printf (XP_TEXT("%s["), ((xp_awk_nde_idx_t*)nde)->id.name); } - __print_expr_node (((xp_awk_node_idx_t*)node)->idx); + __print_expr_nde (((xp_awk_nde_idx_t*)nde)->idx); xp_printf (XP_TEXT("]")); break; - case XP_AWK_NODE_LOCAL: - if (((xp_awk_node_var_t*)node)->id.idxa != (xp_size_t)-1) { + case XP_AWK_NDE_LOCAL: + if (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1) { xp_printf (XP_TEXT("__local%lu"), - (unsigned long)((xp_awk_node_var_t*)node)->id.idxa); + (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa); } else { - xp_printf (XP_TEXT("%s"), ((xp_awk_node_var_t*)node)->id.name); + xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name); } break; - case XP_AWK_NODE_LOCALIDX: - if (((xp_awk_node_idx_t*)node)->id.idxa != (xp_size_t)-1) { + case XP_AWK_NDE_LOCALIDX: + if (((xp_awk_nde_idx_t*)nde)->id.idxa != (xp_size_t)-1) { xp_printf (XP_TEXT("__local%lu["), - (unsigned long)((xp_awk_node_idx_t*)node)->id.idxa); + (unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa); } else { - xp_printf (XP_TEXT("%s["), ((xp_awk_node_idx_t*)node)->id.name); + xp_printf (XP_TEXT("%s["), ((xp_awk_nde_idx_t*)nde)->id.name); } - __print_expr_node (((xp_awk_node_idx_t*)node)->idx); + __print_expr_nde (((xp_awk_nde_idx_t*)nde)->idx); xp_printf (XP_TEXT("]")); break; - case XP_AWK_NODE_POS: + case XP_AWK_NDE_POS: xp_printf (XP_TEXT("$")); - __print_expr_node (((xp_awk_node_sgv_t*)node)->value); + __print_expr_nde (((xp_awk_nde_sgv_t*)nde)->value); break; - case XP_AWK_NODE_CALL: - xp_printf (XP_TEXT("%s ("), ((xp_awk_node_call_t*)node)->name); - if (__print_expr_node_list (((xp_awk_node_call_t*)node)->args) == -1) return -1; + case XP_AWK_NDE_CALL: + xp_printf (XP_TEXT("%s ("), ((xp_awk_nde_call_t*)nde)->name); + if (__print_expr_nde_list (((xp_awk_nde_call_t*)nde)->args) == -1) return -1; xp_printf (XP_TEXT(")")); break; @@ -161,12 +161,12 @@ static int __print_expr_node (xp_awk_node_t* node) return 0; } -static int __print_expr_node_list (xp_awk_node_t* tree) +static int __print_expr_nde_list (xp_awk_nde_t* tree) { - xp_awk_node_t* p = tree; + xp_awk_nde_t* p = tree; while (p != XP_NULL) { - if (__print_expr_node (p) == -1) return -1; + if (__print_expr_nde (p) == -1) return -1; p = p->next; if (p != XP_NULL) xp_printf (XP_TEXT(",")); } @@ -174,171 +174,171 @@ static int __print_expr_node_list (xp_awk_node_t* tree) return 0; } -static void __print_statements (xp_awk_node_t* tree, int depth) +static void __print_statements (xp_awk_nde_t* tree, int depth) { - xp_awk_node_t* p = tree; + xp_awk_nde_t* p = tree; xp_size_t i; while (p != XP_NULL) { switch (p->type) { - case XP_AWK_NODE_NULL: + case XP_AWK_NDE_NULL: __print_tabs (depth); xp_printf (XP_TEXT(";\n")); break; - case XP_AWK_NODE_BLOCK: + case XP_AWK_NDE_BLOCK: __print_tabs (depth); xp_printf (XP_TEXT("{\n")); - if (((xp_awk_node_block_t*)p)->nlocals > 0) { + if (((xp_awk_nde_block_t*)p)->nlocals > 0) { __print_tabs (depth + 1); xp_printf (XP_TEXT("local ")); - for (i = 0; i < ((xp_awk_node_block_t*)p)->nlocals - 1; i++) { + for (i = 0; i < ((xp_awk_nde_block_t*)p)->nlocals - 1; i++) { xp_printf (XP_TEXT("__local%lu, "), (unsigned long)i); } xp_printf (XP_TEXT("__local%lu;\n"), (unsigned long)i); } - __print_statements (((xp_awk_node_block_t*)p)->body, depth + 1); + __print_statements (((xp_awk_nde_block_t*)p)->body, depth + 1); __print_tabs (depth); xp_printf (XP_TEXT("}\n")); break; - case XP_AWK_NODE_IF: + case XP_AWK_NDE_IF: __print_tabs (depth); xp_printf (XP_TEXT("if (")); - __print_expr_node (((xp_awk_node_if_t*)p)->test); + __print_expr_nde (((xp_awk_nde_if_t*)p)->test); xp_printf (XP_TEXT(")\n")); - xp_assert (((xp_awk_node_if_t*)p)->then_part != XP_NULL); - if (((xp_awk_node_if_t*)p)->then_part->type == XP_AWK_NODE_BLOCK) - __print_statements (((xp_awk_node_if_t*)p)->then_part, depth); + xp_assert (((xp_awk_nde_if_t*)p)->then_part != XP_NULL); + if (((xp_awk_nde_if_t*)p)->then_part->type == XP_AWK_NDE_BLOCK) + __print_statements (((xp_awk_nde_if_t*)p)->then_part, depth); else - __print_statements (((xp_awk_node_if_t*)p)->then_part, depth + 1); + __print_statements (((xp_awk_nde_if_t*)p)->then_part, depth + 1); - if (((xp_awk_node_if_t*)p)->else_part != XP_NULL) { + if (((xp_awk_nde_if_t*)p)->else_part != XP_NULL) { __print_tabs (depth); xp_printf (XP_TEXT("else\n")); - if (((xp_awk_node_if_t*)p)->else_part->type == XP_AWK_NODE_BLOCK) - __print_statements (((xp_awk_node_if_t*)p)->else_part, depth); + if (((xp_awk_nde_if_t*)p)->else_part->type == XP_AWK_NDE_BLOCK) + __print_statements (((xp_awk_nde_if_t*)p)->else_part, depth); else - __print_statements (((xp_awk_node_if_t*)p)->else_part, depth + 1); + __print_statements (((xp_awk_nde_if_t*)p)->else_part, depth + 1); } break; - case XP_AWK_NODE_WHILE: + case XP_AWK_NDE_WHILE: __print_tabs (depth); xp_printf (XP_TEXT("while (")); - __print_expr_node (((xp_awk_node_while_t*)p)->test); + __print_expr_nde (((xp_awk_nde_while_t*)p)->test); xp_printf (XP_TEXT(")\n")); - if (((xp_awk_node_while_t*)p)->body->type == XP_AWK_NODE_BLOCK) { - __print_statements (((xp_awk_node_while_t*)p)->body, depth); + if (((xp_awk_nde_while_t*)p)->body->type == XP_AWK_NDE_BLOCK) { + __print_statements (((xp_awk_nde_while_t*)p)->body, depth); } else { - __print_statements (((xp_awk_node_while_t*)p)->body, depth + 1); + __print_statements (((xp_awk_nde_while_t*)p)->body, depth + 1); } break; - case XP_AWK_NODE_DOWHILE: + case XP_AWK_NDE_DOWHILE: __print_tabs (depth); xp_printf (XP_TEXT("do\n")); - if (((xp_awk_node_while_t*)p)->body->type == XP_AWK_NODE_BLOCK) { - __print_statements (((xp_awk_node_while_t*)p)->body, depth); + if (((xp_awk_nde_while_t*)p)->body->type == XP_AWK_NDE_BLOCK) { + __print_statements (((xp_awk_nde_while_t*)p)->body, depth); } else { - __print_statements (((xp_awk_node_while_t*)p)->body, depth + 1); + __print_statements (((xp_awk_nde_while_t*)p)->body, depth + 1); } __print_tabs (depth); xp_printf (XP_TEXT("while (")); - __print_expr_node (((xp_awk_node_while_t*)p)->test); + __print_expr_nde (((xp_awk_nde_while_t*)p)->test); xp_printf (XP_TEXT(");\n")); break; - case XP_AWK_NODE_FOR: + case XP_AWK_NDE_FOR: __print_tabs (depth); xp_printf (XP_TEXT("for (")); - if (((xp_awk_node_for_t*)p)->init != XP_NULL) { - __print_expr_node (((xp_awk_node_for_t*)p)->init); + if (((xp_awk_nde_for_t*)p)->init != XP_NULL) { + __print_expr_nde (((xp_awk_nde_for_t*)p)->init); } xp_printf (XP_TEXT("; ")); - if (((xp_awk_node_for_t*)p)->test != XP_NULL) { - __print_expr_node (((xp_awk_node_for_t*)p)->test); + if (((xp_awk_nde_for_t*)p)->test != XP_NULL) { + __print_expr_nde (((xp_awk_nde_for_t*)p)->test); } xp_printf (XP_TEXT("; ")); - if (((xp_awk_node_for_t*)p)->incr != XP_NULL) { - __print_expr_node (((xp_awk_node_for_t*)p)->incr); + if (((xp_awk_nde_for_t*)p)->incr != XP_NULL) { + __print_expr_nde (((xp_awk_nde_for_t*)p)->incr); } xp_printf (XP_TEXT(")\n")); - if (((xp_awk_node_for_t*)p)->body->type == XP_AWK_NODE_BLOCK) { - __print_statements (((xp_awk_node_for_t*)p)->body, depth); + if (((xp_awk_nde_for_t*)p)->body->type == XP_AWK_NDE_BLOCK) { + __print_statements (((xp_awk_nde_for_t*)p)->body, depth); } else { - __print_statements (((xp_awk_node_for_t*)p)->body, depth + 1); + __print_statements (((xp_awk_nde_for_t*)p)->body, depth + 1); } - case XP_AWK_NODE_BREAK: + case XP_AWK_NDE_BREAK: __print_tabs (depth); xp_printf (XP_TEXT("break;\n")); break; - case XP_AWK_NODE_CONTINUE: + case XP_AWK_NDE_CONTINUE: __print_tabs (depth); xp_printf (XP_TEXT("continue;\n")); break; - case XP_AWK_NODE_RETURN: + case XP_AWK_NDE_RETURN: __print_tabs (depth); - if (((xp_awk_node_sgv_t*)p)->value == XP_NULL) { + if (((xp_awk_nde_sgv_t*)p)->value == XP_NULL) { xp_printf (XP_TEXT("return;\n")); } else { xp_printf (XP_TEXT("return ")); - xp_assert (((xp_awk_node_sgv_t*)p)->value->next == XP_NULL); - if (__print_expr_node(((xp_awk_node_sgv_t*)p)->value) == 0) { + xp_assert (((xp_awk_nde_sgv_t*)p)->value->next == XP_NULL); + if (__print_expr_nde(((xp_awk_nde_sgv_t*)p)->value) == 0) { xp_printf (XP_TEXT(";\n")); } else { - xp_awk_node_sgv_t* x = (xp_awk_node_sgv_t*)p; - xp_printf (XP_TEXT("***INTERNAL ERROR: unknown node type - %d\n"), x->type); + xp_awk_nde_sgv_t* x = (xp_awk_nde_sgv_t*)p; + xp_printf (XP_TEXT("***INTERNAL ERROR: unknown nde type - %d\n"), x->type); } } break; - case XP_AWK_NODE_EXIT: + case XP_AWK_NDE_EXIT: __print_tabs (depth); - if (((xp_awk_node_sgv_t*)p)->value == XP_NULL) { + if (((xp_awk_nde_sgv_t*)p)->value == XP_NULL) { xp_printf (XP_TEXT("exit;\n")); } else { xp_printf (XP_TEXT("exit ")); - xp_assert (((xp_awk_node_sgv_t*)p)->value->next == XP_NULL); - if (__print_expr_node(((xp_awk_node_sgv_t*)p)->value) == 0) { + xp_assert (((xp_awk_nde_sgv_t*)p)->value->next == XP_NULL); + if (__print_expr_nde(((xp_awk_nde_sgv_t*)p)->value) == 0) { xp_printf (XP_TEXT(";\n")); } else { - xp_awk_node_sgv_t* x = (xp_awk_node_sgv_t*)p; - xp_printf (XP_TEXT("***INTERNAL ERROR: unknown node type - %d\n"), x->type); + xp_awk_nde_sgv_t* x = (xp_awk_nde_sgv_t*)p; + xp_printf (XP_TEXT("***INTERNAL ERROR: unknown nde type - %d\n"), x->type); } } break; - case XP_AWK_NODE_NEXT: + case XP_AWK_NDE_NEXT: __print_tabs (depth); xp_printf (XP_TEXT("next;\n")); break; - case XP_AWK_NODE_NEXTFILE: + case XP_AWK_NDE_NEXTFILE: __print_tabs (depth); xp_printf (XP_TEXT("nextfile;\n")); break; default: __print_tabs (depth); - if (__print_expr_node(p) == 0) { + if (__print_expr_nde(p) == 0) { xp_printf (XP_TEXT(";\n")); } else { @@ -350,126 +350,126 @@ static void __print_statements (xp_awk_node_t* tree, int depth) } } -void xp_awk_prnpt (xp_awk_node_t* tree) +void xp_awk_prnpt (xp_awk_nde_t* tree) { __print_statements (tree, 0); } -void xp_awk_clrpt (xp_awk_node_t* tree) +void xp_awk_clrpt (xp_awk_nde_t* tree) { - xp_awk_node_t* p = tree; - xp_awk_node_t* next; + xp_awk_nde_t* p = tree; + xp_awk_nde_t* next; while (p != XP_NULL) { next = p->next; switch (p->type) { - case XP_AWK_NODE_NULL: + case XP_AWK_NDE_NULL: xp_free (p); break; - case XP_AWK_NODE_BLOCK: - xp_awk_clrpt (((xp_awk_node_block_t*)p)->body); + case XP_AWK_NDE_BLOCK: + xp_awk_clrpt (((xp_awk_nde_block_t*)p)->body); xp_free (p); break; - case XP_AWK_NODE_IF: - xp_awk_clrpt (((xp_awk_node_if_t*)p)->test); - xp_awk_clrpt (((xp_awk_node_if_t*)p)->then_part); + case XP_AWK_NDE_IF: + xp_awk_clrpt (((xp_awk_nde_if_t*)p)->test); + xp_awk_clrpt (((xp_awk_nde_if_t*)p)->then_part); - if (((xp_awk_node_if_t*)p)->else_part != XP_NULL) - xp_awk_clrpt (((xp_awk_node_if_t*)p)->else_part); + if (((xp_awk_nde_if_t*)p)->else_part != XP_NULL) + xp_awk_clrpt (((xp_awk_nde_if_t*)p)->else_part); xp_free (p); break; - case XP_AWK_NODE_WHILE: - case XP_AWK_NODE_DOWHILE: - xp_awk_clrpt (((xp_awk_node_while_t*)p)->test); - xp_awk_clrpt (((xp_awk_node_while_t*)p)->body); + case XP_AWK_NDE_WHILE: + case XP_AWK_NDE_DOWHILE: + xp_awk_clrpt (((xp_awk_nde_while_t*)p)->test); + xp_awk_clrpt (((xp_awk_nde_while_t*)p)->body); xp_free (p); break; - case XP_AWK_NODE_FOR: - if (((xp_awk_node_for_t*)p)->init != XP_NULL) - xp_awk_clrpt (((xp_awk_node_for_t*)p)->init); - if (((xp_awk_node_for_t*)p)->test != XP_NULL) - xp_awk_clrpt (((xp_awk_node_for_t*)p)->test); - if (((xp_awk_node_for_t*)p)->incr != XP_NULL) - xp_awk_clrpt (((xp_awk_node_for_t*)p)->incr); - xp_awk_clrpt (((xp_awk_node_for_t*)p)->body); + case XP_AWK_NDE_FOR: + if (((xp_awk_nde_for_t*)p)->init != XP_NULL) + xp_awk_clrpt (((xp_awk_nde_for_t*)p)->init); + if (((xp_awk_nde_for_t*)p)->test != XP_NULL) + xp_awk_clrpt (((xp_awk_nde_for_t*)p)->test); + if (((xp_awk_nde_for_t*)p)->incr != XP_NULL) + xp_awk_clrpt (((xp_awk_nde_for_t*)p)->incr); + xp_awk_clrpt (((xp_awk_nde_for_t*)p)->body); xp_free (p); break; - case XP_AWK_NODE_BREAK: - case XP_AWK_NODE_CONTINUE: - case XP_AWK_NODE_NEXT: - case XP_AWK_NODE_NEXTFILE: + case XP_AWK_NDE_BREAK: + case XP_AWK_NDE_CONTINUE: + case XP_AWK_NDE_NEXT: + case XP_AWK_NDE_NEXTFILE: xp_free (p); break; - case XP_AWK_NODE_RETURN: - case XP_AWK_NODE_EXIT: - if (((xp_awk_node_sgv_t*)p)->value != XP_NULL) - xp_awk_clrpt (((xp_awk_node_sgv_t*)p)->value); + case XP_AWK_NDE_RETURN: + case XP_AWK_NDE_EXIT: + if (((xp_awk_nde_sgv_t*)p)->value != XP_NULL) + xp_awk_clrpt (((xp_awk_nde_sgv_t*)p)->value); xp_free (p); break; - case XP_AWK_NODE_ASSIGN: - xp_awk_clrpt (((xp_awk_node_assign_t*)p)->left); - xp_awk_clrpt (((xp_awk_node_assign_t*)p)->right); + case XP_AWK_NDE_ASS: + xp_awk_clrpt (((xp_awk_nde_ass_t*)p)->left); + xp_awk_clrpt (((xp_awk_nde_ass_t*)p)->right); xp_free (p); break; - case XP_AWK_NODE_BINARY: - xp_assert ((((xp_awk_node_expr_t*)p)->left)->next == XP_NULL); - xp_assert ((((xp_awk_node_expr_t*)p)->right)->next == XP_NULL); + case XP_AWK_NDE_BINARY: + xp_assert ((((xp_awk_nde_expr_t*)p)->left)->next == XP_NULL); + xp_assert ((((xp_awk_nde_expr_t*)p)->right)->next == XP_NULL); - xp_awk_clrpt (((xp_awk_node_expr_t*)p)->left); - xp_awk_clrpt (((xp_awk_node_expr_t*)p)->right); + xp_awk_clrpt (((xp_awk_nde_expr_t*)p)->left); + xp_awk_clrpt (((xp_awk_nde_expr_t*)p)->right); xp_free (p); break; - case XP_AWK_NODE_UNARY: + case XP_AWK_NDE_UNARY: // TODO: clear unary expression... xp_free (p); break; - case XP_AWK_NODE_STR: - case XP_AWK_NODE_NUM: - xp_free (((xp_awk_node_term_t*)p)->value); + case XP_AWK_NDE_STR: + case XP_AWK_NDE_NUM: + xp_free (((xp_awk_nde_term_t*)p)->value); xp_free (p); break; - case XP_AWK_NODE_NAMED: - xp_assert (((xp_awk_node_idx_t*)p)->id.name != XP_NULL); - case XP_AWK_NODE_GLOBAL: - case XP_AWK_NODE_LOCAL: - case XP_AWK_NODE_ARG: - if (((xp_awk_node_var_t*)p)->id.name != XP_NULL) - xp_free (((xp_awk_node_var_t*)p)->id.name); + case XP_AWK_NDE_NAMED: + xp_assert (((xp_awk_nde_idx_t*)p)->id.name != XP_NULL); + case XP_AWK_NDE_GLOBAL: + case XP_AWK_NDE_LOCAL: + case XP_AWK_NDE_ARG: + if (((xp_awk_nde_var_t*)p)->id.name != XP_NULL) + xp_free (((xp_awk_nde_var_t*)p)->id.name); xp_free (p); break; - case XP_AWK_NODE_NAMEDIDX: - xp_assert (((xp_awk_node_idx_t*)p)->id.name != XP_NULL); - case XP_AWK_NODE_GLOBALIDX: - case XP_AWK_NODE_LOCALIDX: - case XP_AWK_NODE_ARGIDX: - xp_awk_clrpt (((xp_awk_node_idx_t*)p)->idx); - if (((xp_awk_node_idx_t*)p)->id.name != XP_NULL) - xp_free (((xp_awk_node_idx_t*)p)->id.name); + case XP_AWK_NDE_NAMEDIDX: + xp_assert (((xp_awk_nde_idx_t*)p)->id.name != XP_NULL); + case XP_AWK_NDE_GLOBALIDX: + case XP_AWK_NDE_LOCALIDX: + case XP_AWK_NDE_ARGIDX: + xp_awk_clrpt (((xp_awk_nde_idx_t*)p)->idx); + if (((xp_awk_nde_idx_t*)p)->id.name != XP_NULL) + xp_free (((xp_awk_nde_idx_t*)p)->id.name); xp_free (p); break; - case XP_AWK_NODE_POS: - xp_assert (((xp_awk_node_sgv_t*)p)->value != XP_NULL); - xp_awk_clrpt (((xp_awk_node_sgv_t*)p)->value); + case XP_AWK_NDE_POS: + xp_assert (((xp_awk_nde_sgv_t*)p)->value != XP_NULL); + xp_awk_clrpt (((xp_awk_nde_sgv_t*)p)->value); xp_free (p); break; - case XP_AWK_NODE_CALL: - xp_free (((xp_awk_node_call_t*)p)->name); - xp_awk_clrpt (((xp_awk_node_call_t*)p)->args); + case XP_AWK_NDE_CALL: + xp_free (((xp_awk_nde_call_t*)p)->name); + xp_awk_clrpt (((xp_awk_nde_call_t*)p)->args); xp_free (p); break; diff --git a/ase/awk/tree.h b/ase/awk/tree.h index 14b7b167..44d90c05 100644 --- a/ase/awk/tree.h +++ b/ase/awk/tree.h @@ -1,167 +1,171 @@ /* - * $Id: tree.h,v 1.22 2006-02-05 16:00:33 bacon Exp $ + * $Id: tree.h,v 1.23 2006-03-03 11:45:45 bacon Exp $ */ #ifndef _XP_AWK_TREE_H_ #define _XP_AWK_TREE_H_ +#ifndef _XP_AWK_AWK_H_ +#error Never include this file directly. Include instead +#endif + enum { - XP_AWK_NODE_NULL, - XP_AWK_NODE_BLOCK, - XP_AWK_NODE_BREAK, - XP_AWK_NODE_CONTINUE, - XP_AWK_NODE_RETURN, - XP_AWK_NODE_EXIT, - XP_AWK_NODE_NEXT, - XP_AWK_NODE_NEXTFILE, - XP_AWK_NODE_ASSIGN, - XP_AWK_NODE_BINARY, - XP_AWK_NODE_UNARY, - XP_AWK_NODE_STR, - XP_AWK_NODE_NUM, - XP_AWK_NODE_NAMED, - XP_AWK_NODE_NAMEDIDX, - XP_AWK_NODE_GLOBAL, - XP_AWK_NODE_GLOBALIDX, - XP_AWK_NODE_LOCAL, - XP_AWK_NODE_LOCALIDX, - XP_AWK_NODE_ARG, - XP_AWK_NODE_ARGIDX, - XP_AWK_NODE_POS, - XP_AWK_NODE_CALL, - XP_AWK_NODE_IF, - XP_AWK_NODE_WHILE, - XP_AWK_NODE_DOWHILE, - XP_AWK_NODE_FOR + XP_AWK_NDE_NULL, + XP_AWK_NDE_BLOCK, + XP_AWK_NDE_BREAK, + XP_AWK_NDE_CONTINUE, + XP_AWK_NDE_RETURN, + XP_AWK_NDE_EXIT, + XP_AWK_NDE_NEXT, + XP_AWK_NDE_NEXTFILE, + XP_AWK_NDE_ASS, + XP_AWK_NDE_BINARY, + XP_AWK_NDE_UNARY, + XP_AWK_NDE_STR, + XP_AWK_NDE_NUM, + XP_AWK_NDE_NAMED, + XP_AWK_NDE_NAMEDIDX, + XP_AWK_NDE_GLOBAL, + XP_AWK_NDE_GLOBALIDX, + XP_AWK_NDE_LOCAL, + XP_AWK_NDE_LOCALIDX, + XP_AWK_NDE_ARG, + XP_AWK_NDE_ARGIDX, + XP_AWK_NDE_POS, + XP_AWK_NDE_CALL, + XP_AWK_NDE_IF, + XP_AWK_NDE_WHILE, + XP_AWK_NDE_DOWHILE, + XP_AWK_NDE_FOR }; typedef struct xp_awk_func_t xp_awk_func_t; -typedef struct xp_awk_node_t xp_awk_node_t; -typedef struct xp_awk_node_sgv_t xp_awk_node_sgv_t; -typedef struct xp_awk_node_block_t xp_awk_node_block_t; -typedef struct xp_awk_node_assign_t xp_awk_node_assign_t; -typedef struct xp_awk_node_expr_t xp_awk_node_expr_t; -typedef struct xp_awk_node_term_t xp_awk_node_term_t; -typedef struct xp_awk_node_var_t xp_awk_node_var_t; -typedef struct xp_awk_node_idx_t xp_awk_node_idx_t; -typedef struct xp_awk_node_pos_t xp_awk_node_pos_t; -typedef struct xp_awk_node_call_t xp_awk_node_call_t; -typedef struct xp_awk_node_if_t xp_awk_node_if_t; -typedef struct xp_awk_node_while_t xp_awk_node_while_t; -typedef struct xp_awk_node_for_t xp_awk_node_for_t; +typedef struct xp_awk_nde_t xp_awk_nde_t; +typedef struct xp_awk_nde_sgv_t xp_awk_nde_sgv_t; +typedef struct xp_awk_nde_block_t xp_awk_nde_block_t; +typedef struct xp_awk_nde_ass_t xp_awk_nde_ass_t; +typedef struct xp_awk_nde_expr_t xp_awk_nde_expr_t; +typedef struct xp_awk_nde_term_t xp_awk_nde_term_t; +typedef struct xp_awk_nde_var_t xp_awk_nde_var_t; +typedef struct xp_awk_nde_idx_t xp_awk_nde_idx_t; +typedef struct xp_awk_nde_pos_t xp_awk_nde_pos_t; +typedef struct xp_awk_nde_call_t xp_awk_nde_call_t; +typedef struct xp_awk_nde_if_t xp_awk_nde_if_t; +typedef struct xp_awk_nde_while_t xp_awk_nde_while_t; +typedef struct xp_awk_nde_for_t xp_awk_nde_for_t; struct xp_awk_func_t { xp_char_t* name; xp_size_t nargs; - xp_awk_node_t* body; + xp_awk_nde_t* body; }; -#define XP_AWK_NODE_HDR \ +#define XP_AWK_NDE_HDR \ int type; \ - xp_awk_node_t* next + xp_awk_nde_t* next -struct xp_awk_node_t +struct xp_awk_nde_t { - XP_AWK_NODE_HDR; + XP_AWK_NDE_HDR; }; -/* XP_AWK_NODE_RETURN, XP_AWK_NODE_EXIT, XP_AWK_NODE_POS */ -struct xp_awk_node_sgv_t +/* XP_AWK_NDE_RETURN, XP_AWK_NDE_EXIT, XP_AWK_NDE_POS */ +struct xp_awk_nde_sgv_t { - XP_AWK_NODE_HDR; - xp_awk_node_t* value; + XP_AWK_NDE_HDR; + xp_awk_nde_t* value; }; -struct xp_awk_node_block_t +struct xp_awk_nde_block_t { - XP_AWK_NODE_HDR; + XP_AWK_NDE_HDR; xp_size_t nlocals; - xp_awk_node_t* body; + xp_awk_nde_t* body; }; -struct xp_awk_node_assign_t +struct xp_awk_nde_ass_t { - XP_AWK_NODE_HDR; - xp_awk_node_t* left; - xp_awk_node_t* right; + XP_AWK_NDE_HDR; + xp_awk_nde_t* left; + xp_awk_nde_t* right; }; -struct xp_awk_node_expr_t +struct xp_awk_nde_expr_t { - XP_AWK_NODE_HDR; + XP_AWK_NDE_HDR; int opcode; - xp_awk_node_t* left; - xp_awk_node_t* right; + xp_awk_nde_t* left; + xp_awk_nde_t* right; }; -struct xp_awk_node_term_t +struct xp_awk_nde_term_t { - XP_AWK_NODE_HDR; + XP_AWK_NDE_HDR; xp_char_t* value; }; -struct xp_awk_node_var_t +struct xp_awk_nde_var_t { - XP_AWK_NODE_HDR; - struct // uniion - { - xp_char_t* name; - xp_size_t idxa; - } id; -}; - -struct xp_awk_node_idx_t -{ - XP_AWK_NODE_HDR; + XP_AWK_NDE_HDR; struct // union { xp_char_t* name; xp_size_t idxa; } id; - xp_awk_node_t* idx; +}; + +struct xp_awk_nde_idx_t +{ + XP_AWK_NDE_HDR; + struct // union + { + xp_char_t* name; + xp_size_t idxa; + } id; + xp_awk_nde_t* idx; }; -struct xp_awk_node_call_t +struct xp_awk_nde_call_t { - XP_AWK_NODE_HDR; /* XP_AWK_NODE_CALL */ + XP_AWK_NDE_HDR; /* XP_AWK_NDE_CALL */ xp_char_t* name; - xp_awk_node_t* args; + xp_awk_nde_t* args; }; -struct xp_awk_node_if_t +struct xp_awk_nde_if_t { - XP_AWK_NODE_HDR; /* XP_AWK_NODE_IF */ - xp_awk_node_t* test; - xp_awk_node_t* then_part; - xp_awk_node_t* else_part; /* optional */ + XP_AWK_NDE_HDR; /* XP_AWK_NDE_IF */ + xp_awk_nde_t* test; + xp_awk_nde_t* then_part; + xp_awk_nde_t* else_part; /* optional */ }; -struct xp_awk_node_while_t +struct xp_awk_nde_while_t { - XP_AWK_NODE_HDR; /* XP_AWK_NODE_WHILE, XP_AWK_NODE_DOWHILE */ - xp_awk_node_t* test; - xp_awk_node_t* body; + XP_AWK_NDE_HDR; /* XP_AWK_NDE_WHILE, XP_AWK_NDE_DOWHILE */ + xp_awk_nde_t* test; + xp_awk_nde_t* body; }; -struct xp_awk_node_for_t +struct xp_awk_nde_for_t { - XP_AWK_NODE_HDR; /* XP_AWK_NODE_FOR */ - xp_awk_node_t* init; /* optional */ - xp_awk_node_t* test; /* optional */ - xp_awk_node_t* incr; /* optional */ - xp_awk_node_t* body; + XP_AWK_NDE_HDR; /* XP_AWK_NDE_FOR */ + xp_awk_nde_t* init; /* optional */ + xp_awk_nde_t* test; /* optional */ + xp_awk_nde_t* incr; /* optional */ + xp_awk_nde_t* body; }; #ifdef __cplusplus extern "C" { #endif -void xp_awk_prnpt (xp_awk_node_t* tree); -void xp_awk_clrpt (xp_awk_node_t* tree); +void xp_awk_prnpt (xp_awk_nde_t* tree); +void xp_awk_clrpt (xp_awk_nde_t* tree); #ifdef __cplusplus } diff --git a/ase/awk/val.h b/ase/awk/val.h new file mode 100644 index 00000000..fbddb436 --- /dev/null +++ b/ase/awk/val.h @@ -0,0 +1,44 @@ +/* + * $Id: val.h,v 1.1 2006-03-03 11:45:45 bacon Exp $ + */ + +#ifndef _XP_AWK_VAL_H_ +#define _XP_AWK_VAL_H_ + +#ifndef _XP_AWK_AWK_H_ +#error Never include this file directly. Include instead +#endif + +typedef struct xp_awk_val_t xp_awk_val_t; +typedef struct xp_awk_val_int_t xp_awk_val_int_t; +typedef struct xp_awk_val_real_t xp_awk_val_real_t; +typedef struct xp_awk_val_str_t xp_awk_val_str_t; + +#define XP_AWK_VAL_HDR \ + int type + +struct xp_awk_val_t +{ + XP_AWK_VAL_HDR; +}; + +struct xp_awk_val_int_t +{ + XP_AWK_VAL_HDR; + xp_long_t val; +}; + +struct xp_awk_val_real_t +{ + XP_AWK_VAL_HDR; + xp_real_t val; +}; + +struct xp_awk_val_str_t +{ + XP_AWK_VAL_HDR; + xp_char_t* buf; + xp_size_t len; +}; + +#endif