*** empty log message ***
This commit is contained in:
parent
8b10964885
commit
af63818095
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: parse.c,v 1.101 2006-05-06 12:52:36 bacon Exp $
|
* $Id: parse.c,v 1.102 2006-05-07 17:45:08 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -107,7 +107,7 @@ static xp_awk_t* __collect_locals (xp_awk_t* awk, xp_size_t nlocals);
|
|||||||
static xp_awk_nde_t* __parse_function (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_begin (xp_awk_t* awk);
|
||||||
static xp_awk_nde_t* __parse_end (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_nde_t* __parse_ptnblock (xp_awk_t* awk, xp_awk_nde_t* ptn);
|
||||||
|
|
||||||
static xp_awk_nde_t* __parse_action (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_block (xp_awk_t* awk, xp_bool_t is_top);
|
||||||
@ -315,8 +315,17 @@ static void __dump (xp_awk_t* awk)
|
|||||||
chain = awk->tree.chain;
|
chain = awk->tree.chain;
|
||||||
while (chain != XP_NULL)
|
while (chain != XP_NULL)
|
||||||
{
|
{
|
||||||
if (chain->pattern != XP_NULL) xp_awk_prnpt (chain->pattern);
|
if (chain->pattern != XP_NULL)
|
||||||
if (chain->action != XP_NULL) xp_awk_prnpt (chain->action);
|
{
|
||||||
|
/*xp_awk_prnpt (chain->pattern);*/
|
||||||
|
xp_awk_prnptnpt (chain->pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chain->action != XP_NULL)
|
||||||
|
{
|
||||||
|
xp_awk_prnpt (chain->action);
|
||||||
|
}
|
||||||
|
|
||||||
xp_printf (XP_T("\n"));
|
xp_printf (XP_T("\n"));
|
||||||
chain = chain->next;
|
chain = chain->next;
|
||||||
}
|
}
|
||||||
@ -398,11 +407,11 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk)
|
|||||||
}
|
}
|
||||||
else if (MATCH(awk,TOKEN_LBRACE))
|
else if (MATCH(awk,TOKEN_LBRACE))
|
||||||
{
|
{
|
||||||
if (__parse_patternless(awk) == XP_NULL) return XP_NULL;
|
/* pattern less block */
|
||||||
|
if (__parse_ptnblock(awk,XP_NULL) == XP_NULL) return XP_NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* TODO: process patterns and expressions */
|
|
||||||
/*
|
/*
|
||||||
expressions
|
expressions
|
||||||
/regular expression/
|
/regular expression/
|
||||||
@ -412,17 +421,43 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk)
|
|||||||
(pattern)
|
(pattern)
|
||||||
pattern, pattern
|
pattern, pattern
|
||||||
*/
|
*/
|
||||||
|
xp_awk_nde_t* ptn;
|
||||||
|
|
||||||
|
ptn = __parse_expression (awk);
|
||||||
|
if (ptn == XP_NULL) return XP_NULL;
|
||||||
|
|
||||||
|
xp_assert (ptn->next == XP_NULL);
|
||||||
|
|
||||||
|
if (MATCH(awk,TOKEN_COMMA))
|
||||||
|
{
|
||||||
|
if (__get_token(awk) == -1)
|
||||||
|
{
|
||||||
|
xp_awk_clrpt (ptn);
|
||||||
|
return XP_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptn->next = __parse_expression (awk);
|
||||||
|
if (ptn->next == XP_NULL)
|
||||||
|
{
|
||||||
|
xp_awk_clrpt (ptn);
|
||||||
|
return XP_NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (__parse_expression (awk) == XP_NULL) return XP_NULL;
|
|
||||||
if (MATCH(awk,TOKEN_LBRACE))
|
if (MATCH(awk,TOKEN_LBRACE))
|
||||||
{
|
{
|
||||||
if (__parse_patternless(awk) == XP_NULL) return XP_NULL;
|
if (__parse_ptnblock (awk,ptn) == XP_NULL)
|
||||||
|
{
|
||||||
|
xp_awk_clrpt (ptn);
|
||||||
|
return XP_NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* { print $0; } */
|
/* pattern without a block */
|
||||||
/* TODO: XXXX */
|
/* TODO: ... pattern { print $0; }*/
|
||||||
xp_printf (XP_T("BLOCKLESS NOT IMPLEMENTED....\n"));
|
xp_awk_clrpt (ptn);
|
||||||
|
xp_printf (XP_T("BLOCKLESS NOT IMPLEMENTED\n"));
|
||||||
PANIC (awk, XP_AWK_EINTERNAL);
|
PANIC (awk, XP_AWK_EINTERNAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -672,7 +707,7 @@ static xp_awk_nde_t* __parse_end (xp_awk_t* awk)
|
|||||||
return nde;
|
return nde;
|
||||||
}
|
}
|
||||||
|
|
||||||
static xp_awk_nde_t* __parse_patternless (xp_awk_t* awk)
|
static xp_awk_nde_t* __parse_ptnblock (xp_awk_t* awk, xp_awk_nde_t* ptn)
|
||||||
{
|
{
|
||||||
xp_awk_nde_t* nde;
|
xp_awk_nde_t* nde;
|
||||||
xp_awk_chain_t* chain;
|
xp_awk_chain_t* chain;
|
||||||
@ -687,7 +722,7 @@ static xp_awk_nde_t* __parse_patternless (xp_awk_t* awk)
|
|||||||
PANIC (awk, XP_AWK_ENOMEM);
|
PANIC (awk, XP_AWK_ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
chain->pattern = XP_NULL;
|
chain->pattern = ptn;
|
||||||
chain->action = nde;
|
chain->action = nde;
|
||||||
chain->next = XP_NULL;
|
chain->next = XP_NULL;
|
||||||
|
|
||||||
@ -2897,7 +2932,7 @@ static int __get_token (xp_awk_t* awk)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
xp_printf (XP_T("token -> [%s]\n"), XP_STR_BUF(&awk->token.name));
|
/*xp_printf (XP_T("token -> [%s]\n"), XP_STR_BUF(&awk->token.name));*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: run.c,v 1.86 2006-05-06 12:52:36 bacon Exp $
|
* $Id: run.c,v 1.87 2006-05-07 17:45:08 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -603,6 +603,11 @@ static int __run_if_statement (xp_awk_run_t* run, xp_awk_nde_if_t* nde)
|
|||||||
xp_awk_val_t* test;
|
xp_awk_val_t* test;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
|
/* the test expression for the if statement cannot have
|
||||||
|
* chained expressions. this should not be allowed by the
|
||||||
|
* parser first of all */
|
||||||
|
xp_assert (nde->test->next == XP_NULL);
|
||||||
|
|
||||||
test = __eval_expression (run, nde->test);
|
test = __eval_expression (run, nde->test);
|
||||||
if (test == XP_NULL) return -1;
|
if (test == XP_NULL) return -1;
|
||||||
|
|
||||||
@ -626,6 +631,10 @@ static int __run_while_statement (xp_awk_run_t* run, xp_awk_nde_while_t* nde)
|
|||||||
|
|
||||||
if (nde->type == XP_AWK_NDE_WHILE)
|
if (nde->type == XP_AWK_NDE_WHILE)
|
||||||
{
|
{
|
||||||
|
/* no chained expressions are allowed for the test
|
||||||
|
* expression of the while statement */
|
||||||
|
xp_assert (nde->test->next == XP_NULL);
|
||||||
|
|
||||||
/* TODO: handle run-time abortion... */
|
/* TODO: handle run-time abortion... */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
@ -664,6 +673,10 @@ static int __run_while_statement (xp_awk_run_t* run, xp_awk_nde_while_t* nde)
|
|||||||
}
|
}
|
||||||
else if (nde->type == XP_AWK_NDE_DOWHILE)
|
else if (nde->type == XP_AWK_NDE_DOWHILE)
|
||||||
{
|
{
|
||||||
|
/* no chained expressions are allowed for the test
|
||||||
|
* expression of the while statement */
|
||||||
|
xp_assert (nde->test->next == XP_NULL);
|
||||||
|
|
||||||
/* TODO: handle run-time abortion... */
|
/* TODO: handle run-time abortion... */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -705,6 +718,7 @@ static int __run_for_statement (xp_awk_run_t* run, xp_awk_nde_for_t* nde)
|
|||||||
|
|
||||||
if (nde->init != XP_NULL)
|
if (nde->init != XP_NULL)
|
||||||
{
|
{
|
||||||
|
xp_assert (nde->init->next == XP_NULL);
|
||||||
val = __eval_expression(run,nde->init);
|
val = __eval_expression(run,nde->init);
|
||||||
if (val == XP_NULL) return -1;
|
if (val == XP_NULL) return -1;
|
||||||
|
|
||||||
@ -718,6 +732,10 @@ static int __run_for_statement (xp_awk_run_t* run, xp_awk_nde_for_t* nde)
|
|||||||
{
|
{
|
||||||
xp_awk_val_t* test;
|
xp_awk_val_t* test;
|
||||||
|
|
||||||
|
/* no chained expressions for the test expression of
|
||||||
|
* the for statement are allowed */
|
||||||
|
xp_assert (nde->test->next == XP_NULL);
|
||||||
|
|
||||||
test = __eval_expression (run, nde->test);
|
test = __eval_expression (run, nde->test);
|
||||||
if (test == XP_NULL) return -1;
|
if (test == XP_NULL) return -1;
|
||||||
|
|
||||||
@ -759,6 +777,7 @@ static int __run_for_statement (xp_awk_run_t* run, xp_awk_nde_for_t* nde)
|
|||||||
|
|
||||||
if (nde->incr != XP_NULL)
|
if (nde->incr != XP_NULL)
|
||||||
{
|
{
|
||||||
|
xp_assert (nde->incr->next == XP_NULL);
|
||||||
val = __eval_expression(run,nde->incr);
|
val = __eval_expression(run,nde->incr);
|
||||||
if (val == XP_NULL) return -1;
|
if (val == XP_NULL) return -1;
|
||||||
|
|
||||||
@ -814,6 +833,10 @@ static int __run_foreach_statement (xp_awk_run_t* run, xp_awk_nde_foreach_t* nde
|
|||||||
xp_assert (test->type == XP_AWK_NDE_EXP_BIN &&
|
xp_assert (test->type == XP_AWK_NDE_EXP_BIN &&
|
||||||
test->opcode == XP_AWK_BINOP_IN);
|
test->opcode == XP_AWK_BINOP_IN);
|
||||||
|
|
||||||
|
/* chained expressions should not be allowed
|
||||||
|
* by the parser first of all */
|
||||||
|
xp_assert (test->right->next == XP_NULL);
|
||||||
|
|
||||||
rv = __eval_expression (run, test->right);
|
rv = __eval_expression (run, test->right);
|
||||||
if (rv == XP_NULL) return -1;
|
if (rv == XP_NULL) return -1;
|
||||||
|
|
||||||
@ -852,6 +875,11 @@ static int __run_return_statement (xp_awk_run_t* run, xp_awk_nde_return_t* nde)
|
|||||||
if (nde->val != XP_NULL)
|
if (nde->val != XP_NULL)
|
||||||
{
|
{
|
||||||
xp_awk_val_t* val;
|
xp_awk_val_t* val;
|
||||||
|
|
||||||
|
/* chained expressions should not be allowed
|
||||||
|
* by the parser first of all */
|
||||||
|
xp_assert (nde->val->next == XP_NULL);
|
||||||
|
|
||||||
/*xp_printf (XP_T("returning....\n"));*/
|
/*xp_printf (XP_T("returning....\n"));*/
|
||||||
val = __eval_expression(run, nde->val);
|
val = __eval_expression(run, nde->val);
|
||||||
if (val == XP_NULL) return -1;
|
if (val == XP_NULL) return -1;
|
||||||
@ -873,6 +901,10 @@ static int __run_exit_statement (xp_awk_run_t* run, xp_awk_nde_exit_t* nde)
|
|||||||
{
|
{
|
||||||
xp_awk_val_t* val;
|
xp_awk_val_t* val;
|
||||||
|
|
||||||
|
/* chained expressions should not be allowed
|
||||||
|
* by the parser first of all */
|
||||||
|
xp_assert (nde->val->next == XP_NULL);
|
||||||
|
|
||||||
val = __eval_expression(run, nde->val);
|
val = __eval_expression(run, nde->val);
|
||||||
if (val == XP_NULL) return -1;
|
if (val == XP_NULL) return -1;
|
||||||
|
|
||||||
@ -951,6 +983,7 @@ static xp_awk_val_t* __eval_assignment (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
|||||||
|
|
||||||
xp_assert (ass->left != XP_NULL && ass->right != XP_NULL);
|
xp_assert (ass->left != XP_NULL && ass->right != XP_NULL);
|
||||||
|
|
||||||
|
xp_assert (ass->right->next == XP_NULL);
|
||||||
val = __eval_expression(run, ass->right);
|
val = __eval_expression(run, ass->right);
|
||||||
if (val == XP_NULL) return XP_NULL;
|
if (val == XP_NULL) return XP_NULL;
|
||||||
|
|
||||||
@ -960,6 +993,7 @@ static xp_awk_val_t* __eval_assignment (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
|||||||
{
|
{
|
||||||
xp_awk_val_t* val2, * tmp;
|
xp_awk_val_t* val2, * tmp;
|
||||||
|
|
||||||
|
xp_assert (ass->left->next == XP_NULL);
|
||||||
val2 = __eval_expression (run, ass->left);
|
val2 = __eval_expression (run, ass->left);
|
||||||
if (val2 == XP_NULL)
|
if (val2 == XP_NULL)
|
||||||
{
|
{
|
||||||
@ -1234,11 +1268,13 @@ static xp_awk_val_t* __eval_binary (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
xp_assert (exp->left->next == XP_NULL);
|
||||||
left = __eval_expression (run, exp->left);
|
left = __eval_expression (run, exp->left);
|
||||||
if (left == XP_NULL) return XP_NULL;
|
if (left == XP_NULL) return XP_NULL;
|
||||||
|
|
||||||
xp_awk_refupval (left);
|
xp_awk_refupval (left);
|
||||||
|
|
||||||
|
xp_assert (exp->right->next == XP_NULL);
|
||||||
right = __eval_expression (run, exp->right);
|
right = __eval_expression (run, exp->right);
|
||||||
if (right == XP_NULL)
|
if (right == XP_NULL)
|
||||||
{
|
{
|
||||||
@ -1277,6 +1313,7 @@ static xp_awk_val_t* __eval_binop_lor (
|
|||||||
/* short-circuit evaluation required special treatment */
|
/* short-circuit evaluation required special treatment */
|
||||||
xp_awk_val_t* lv, * rv, * res;
|
xp_awk_val_t* lv, * rv, * res;
|
||||||
|
|
||||||
|
xp_assert (left->next == XP_NULL);
|
||||||
lv = __eval_expression (run, left);
|
lv = __eval_expression (run, left);
|
||||||
if (lv == XP_NULL) return XP_NULL;
|
if (lv == XP_NULL) return XP_NULL;
|
||||||
|
|
||||||
@ -1287,6 +1324,7 @@ static xp_awk_val_t* __eval_binop_lor (
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
xp_assert (right->next == XP_NULL);
|
||||||
rv = __eval_expression (run, right);
|
rv = __eval_expression (run, right);
|
||||||
if (rv == XP_NULL)
|
if (rv == XP_NULL)
|
||||||
{
|
{
|
||||||
@ -1319,6 +1357,7 @@ static xp_awk_val_t* __eval_binop_land (
|
|||||||
/* short-circuit evaluation required special treatment */
|
/* short-circuit evaluation required special treatment */
|
||||||
xp_awk_val_t* lv, * rv, * res;
|
xp_awk_val_t* lv, * rv, * res;
|
||||||
|
|
||||||
|
xp_assert (left->next == XP_NULL);
|
||||||
lv = __eval_expression (run, left);
|
lv = __eval_expression (run, left);
|
||||||
if (lv == XP_NULL) return XP_NULL;
|
if (lv == XP_NULL) return XP_NULL;
|
||||||
|
|
||||||
@ -1329,6 +1368,7 @@ static xp_awk_val_t* __eval_binop_land (
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
xp_assert (right->next == XP_NULL);
|
||||||
rv = __eval_expression (run, right);
|
rv = __eval_expression (run, right);
|
||||||
if (rv == XP_NULL)
|
if (rv == XP_NULL)
|
||||||
{
|
{
|
||||||
@ -1368,6 +1408,7 @@ static xp_awk_val_t* __eval_binop_in (
|
|||||||
if (str == XP_NULL) return XP_NULL;
|
if (str == XP_NULL) return XP_NULL;
|
||||||
|
|
||||||
/* evaluate the right-hand side of the operator */
|
/* evaluate the right-hand side of the operator */
|
||||||
|
xp_assert (right->next == XP_NULL);
|
||||||
rv = __eval_expression (run, right);
|
rv = __eval_expression (run, right);
|
||||||
if (rv == XP_NULL)
|
if (rv == XP_NULL)
|
||||||
{
|
{
|
||||||
@ -2033,7 +2074,7 @@ static xp_awk_val_t* __eval_binop_nm (
|
|||||||
{
|
{
|
||||||
xp_awk_val_t* res;
|
xp_awk_val_t* res;
|
||||||
|
|
||||||
/* TODO: ... */
|
/* TODO: implement nm operator... */
|
||||||
if (left->type == XP_AWK_VAL_REX &&
|
if (left->type == XP_AWK_VAL_REX &&
|
||||||
right->type == XP_AWK_VAL_STR)
|
right->type == XP_AWK_VAL_STR)
|
||||||
{
|
{
|
||||||
@ -2061,6 +2102,7 @@ static xp_awk_val_t* __eval_unary (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
|||||||
xp_assert (exp->type == XP_AWK_NDE_EXP_UNR);
|
xp_assert (exp->type == XP_AWK_NDE_EXP_UNR);
|
||||||
xp_assert (exp->left != XP_NULL && exp->right == XP_NULL);
|
xp_assert (exp->left != XP_NULL && exp->right == XP_NULL);
|
||||||
|
|
||||||
|
xp_assert (exp->left->next == XP_NULL);
|
||||||
left = __eval_expression (run, exp->left);
|
left = __eval_expression (run, exp->left);
|
||||||
if (left == XP_NULL) return XP_NULL;
|
if (left == XP_NULL) return XP_NULL;
|
||||||
|
|
||||||
@ -2167,6 +2209,7 @@ static xp_awk_val_t* __eval_incpre (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
|||||||
PANIC (run, XP_AWK_EOPERAND);
|
PANIC (run, XP_AWK_EOPERAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xp_assert (exp->left->next == XP_NULL);
|
||||||
left = __eval_expression (run, exp->left);
|
left = __eval_expression (run, exp->left);
|
||||||
if (left == XP_NULL) return XP_NULL;
|
if (left == XP_NULL) return XP_NULL;
|
||||||
|
|
||||||
@ -2252,6 +2295,7 @@ static xp_awk_val_t* __eval_incpst (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
|||||||
PANIC (run, XP_AWK_EOPERAND);
|
PANIC (run, XP_AWK_EOPERAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xp_assert (exp->left->next == XP_NULL);
|
||||||
left = __eval_expression (run, exp->left);
|
left = __eval_expression (run, exp->left);
|
||||||
if (left == XP_NULL) return XP_NULL;
|
if (left == XP_NULL) return XP_NULL;
|
||||||
|
|
||||||
@ -2347,11 +2391,14 @@ static xp_awk_val_t* __eval_cnd (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
|||||||
xp_awk_val_t* tv, * v;
|
xp_awk_val_t* tv, * v;
|
||||||
xp_awk_nde_cnd_t* cnd = (xp_awk_nde_cnd_t*)nde;
|
xp_awk_nde_cnd_t* cnd = (xp_awk_nde_cnd_t*)nde;
|
||||||
|
|
||||||
|
xp_assert (cnd->test->next == XP_NULL);
|
||||||
tv = __eval_expression (run, cnd->test);
|
tv = __eval_expression (run, cnd->test);
|
||||||
if (tv == XP_NULL) return XP_NULL;
|
if (tv == XP_NULL) return XP_NULL;
|
||||||
|
|
||||||
xp_awk_refupval (tv);
|
xp_awk_refupval (tv);
|
||||||
|
|
||||||
|
xp_assert (cnd->left->next == XP_NULL &&
|
||||||
|
cnd->right->next == XP_NULL);
|
||||||
v = (xp_awk_boolval(tv))?
|
v = (xp_awk_boolval(tv))?
|
||||||
__eval_expression (run, cnd->left):
|
__eval_expression (run, cnd->left):
|
||||||
__eval_expression (run, cnd->right);
|
__eval_expression (run, cnd->right);
|
||||||
@ -2936,7 +2983,6 @@ static xp_char_t* __idxnde_to_str (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
|||||||
if (nde->next == XP_NULL)
|
if (nde->next == XP_NULL)
|
||||||
{
|
{
|
||||||
/* single node index */
|
/* single node index */
|
||||||
|
|
||||||
idx = __eval_expression (run, nde);
|
idx = __eval_expression (run, nde);
|
||||||
if (idx == XP_NULL) return XP_NULL;
|
if (idx == XP_NULL) return XP_NULL;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: tree.c,v 1.47 2006-05-06 12:52:36 bacon Exp $
|
* $Id: tree.c,v 1.48 2006-05-07 17:45:08 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -99,46 +99,35 @@ static int __print_expression (xp_awk_nde_t* nde)
|
|||||||
|
|
||||||
case XP_AWK_NDE_ASS:
|
case XP_AWK_NDE_ASS:
|
||||||
if (__print_expression (((xp_awk_nde_ass_t*)nde)->left) == -1) return -1;
|
if (__print_expression (((xp_awk_nde_ass_t*)nde)->left) == -1) return -1;
|
||||||
xp_printf (XP_T(" %s "),
|
xp_printf (XP_T(" %s "), __assop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
||||||
__assop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
|
||||||
if (__print_expression (((xp_awk_nde_ass_t*)nde)->right) == -1) return -1;
|
if (__print_expression (((xp_awk_nde_ass_t*)nde)->right) == -1) return -1;
|
||||||
xp_assert ((((xp_awk_nde_ass_t*)nde)->right)->next == XP_NULL);
|
xp_assert ((((xp_awk_nde_ass_t*)nde)->right)->next == XP_NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XP_AWK_NDE_EXP_BIN:
|
case XP_AWK_NDE_EXP_BIN:
|
||||||
xp_printf (XP_T("("));
|
xp_printf (XP_T("("));
|
||||||
if (__print_expression(((xp_awk_nde_exp_t*)nde)->left) == -1)
|
if (__print_expression(((xp_awk_nde_exp_t*)nde)->left) == -1) return -1;
|
||||||
return -1;
|
|
||||||
xp_assert ((((xp_awk_nde_exp_t*)nde)->left)->next == XP_NULL);
|
xp_assert ((((xp_awk_nde_exp_t*)nde)->left)->next == XP_NULL);
|
||||||
xp_printf (XP_T(" %s "),
|
xp_printf (XP_T(" %s "), __binop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
||||||
__binop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
if (((xp_awk_nde_exp_t*)nde)->right->type == XP_AWK_NDE_ASS) xp_printf (XP_T("("));
|
||||||
if (((xp_awk_nde_exp_t*)nde)->right->type == XP_AWK_NDE_ASS)
|
if (__print_expression (((xp_awk_nde_exp_t*)nde)->right) == -1) return -1;
|
||||||
xp_printf (XP_T("("));
|
if (((xp_awk_nde_exp_t*)nde)->right->type == XP_AWK_NDE_ASS) xp_printf (XP_T(")"));
|
||||||
if (__print_expression (((xp_awk_nde_exp_t*)nde)->right) == -1)
|
xp_assert ((((xp_awk_nde_exp_t*)nde)->right)->next == XP_NULL); xp_printf (XP_T(")"));
|
||||||
return -1;
|
|
||||||
if (((xp_awk_nde_exp_t*)nde)->right->type == XP_AWK_NDE_ASS)
|
|
||||||
xp_printf (XP_T(")"));
|
|
||||||
xp_assert ((((xp_awk_nde_exp_t*)nde)->right)->next == XP_NULL);
|
|
||||||
xp_printf (XP_T(")"));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XP_AWK_NDE_EXP_UNR:
|
case XP_AWK_NDE_EXP_UNR:
|
||||||
xp_assert (((xp_awk_nde_exp_t*)nde)->right == XP_NULL);
|
xp_assert (((xp_awk_nde_exp_t*)nde)->right == XP_NULL);
|
||||||
|
|
||||||
xp_printf (XP_T("%s("),
|
xp_printf (XP_T("%s("), __unrop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
||||||
__unrop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
if (__print_expression (((xp_awk_nde_exp_t*)nde)->left) == -1) return -1;
|
||||||
if (__print_expression (((xp_awk_nde_exp_t*)nde)->left) == -1)
|
|
||||||
return -1;
|
|
||||||
xp_printf (XP_T(")"));
|
xp_printf (XP_T(")"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XP_AWK_NDE_EXP_INCPRE:
|
case XP_AWK_NDE_EXP_INCPRE:
|
||||||
xp_assert (((xp_awk_nde_exp_t*)nde)->right == XP_NULL);
|
xp_assert (((xp_awk_nde_exp_t*)nde)->right == XP_NULL);
|
||||||
|
|
||||||
xp_printf (XP_T("%s("),
|
xp_printf (XP_T("%s("), __incop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
||||||
__incop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
if (__print_expression (((xp_awk_nde_exp_t*)nde)->left) == -1) return -1;
|
||||||
if (__print_expression (((xp_awk_nde_exp_t*)nde)->left) == -1)
|
|
||||||
return -1;
|
|
||||||
xp_printf (XP_T(")"));
|
xp_printf (XP_T(")"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -146,23 +135,18 @@ static int __print_expression (xp_awk_nde_t* nde)
|
|||||||
xp_assert (((xp_awk_nde_exp_t*)nde)->right == XP_NULL);
|
xp_assert (((xp_awk_nde_exp_t*)nde)->right == XP_NULL);
|
||||||
|
|
||||||
xp_printf (XP_T("("));
|
xp_printf (XP_T("("));
|
||||||
if (__print_expression (((xp_awk_nde_exp_t*)nde)->left) == -1)
|
if (__print_expression (((xp_awk_nde_exp_t*)nde)->left) == -1) return -1;
|
||||||
return -1;
|
xp_printf (XP_T(")%s"), __incop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
||||||
xp_printf (XP_T(")%s"),
|
|
||||||
__incop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XP_AWK_NDE_CND:
|
case XP_AWK_NDE_CND:
|
||||||
xp_printf (XP_T("("));
|
xp_printf (XP_T("("));
|
||||||
if (__print_expression(((xp_awk_nde_cnd_t*)nde)->test) == -1)
|
if (__print_expression(((xp_awk_nde_cnd_t*)nde)->test) == -1) return -1;
|
||||||
return -1;
|
|
||||||
xp_printf (XP_T(")?"));
|
xp_printf (XP_T(")?"));
|
||||||
|
|
||||||
if (__print_expression(((xp_awk_nde_cnd_t*)nde)->left) == -1)
|
if (__print_expression(((xp_awk_nde_cnd_t*)nde)->left) == -1) return -1;
|
||||||
return -1;
|
|
||||||
xp_printf (XP_T(":"));
|
xp_printf (XP_T(":"));
|
||||||
if (__print_expression(((xp_awk_nde_cnd_t*)nde)->right) == -1)
|
if (__print_expression(((xp_awk_nde_cnd_t*)nde)->right) == -1) return -1;
|
||||||
return -1;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XP_AWK_NDE_INT:
|
case XP_AWK_NDE_INT:
|
||||||
@ -530,6 +514,20 @@ void xp_awk_prnpt (xp_awk_nde_t* tree)
|
|||||||
__print_statements (tree, 0);
|
__print_statements (tree, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void xp_awk_prnptnpt (xp_awk_nde_t* tree)
|
||||||
|
{
|
||||||
|
xp_awk_nde_t* nde = tree;
|
||||||
|
|
||||||
|
while (nde != XP_NULL)
|
||||||
|
{
|
||||||
|
__print_expression (tree);
|
||||||
|
if (nde->next == XP_NULL) break;
|
||||||
|
|
||||||
|
xp_printf (XP_T(","));
|
||||||
|
nde = nde->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void xp_awk_clrpt (xp_awk_nde_t* tree)
|
void xp_awk_clrpt (xp_awk_nde_t* tree)
|
||||||
{
|
{
|
||||||
xp_awk_nde_t* p = tree;
|
xp_awk_nde_t* p = tree;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: tree.h,v 1.40 2006-04-29 12:09:29 bacon Exp $
|
* $Id: tree.h,v 1.41 2006-05-07 17:45:08 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_AWK_TREE_H_
|
#ifndef _XP_AWK_TREE_H_
|
||||||
@ -278,6 +278,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void xp_awk_prnpt (xp_awk_nde_t* tree);
|
void xp_awk_prnpt (xp_awk_nde_t* tree);
|
||||||
|
void xp_awk_prnptnpt (xp_awk_nde_t* tree);
|
||||||
void xp_awk_clrpt (xp_awk_nde_t* tree);
|
void xp_awk_clrpt (xp_awk_nde_t* tree);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Loading…
x
Reference in New Issue
Block a user