*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-11 09:16:20 +00:00
parent 951a4bb95b
commit ff4f09f03f
4 changed files with 79 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.76 2006-04-10 15:52:07 bacon Exp $
* $Id: parse.c,v 1.77 2006-04-11 09:16:20 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -1064,12 +1064,15 @@ static xp_awk_nde_t* __parse_basic_expr (xp_awk_t* awk)
if (MATCH(awk,TOKEN_QUEST))
{
xp_awk_nde_cnd_t* tmp;
if (__get_token(awk) == -1) return XP_NULL;
n1 = __parse_basic_expr (awk);
if (n1 == XP_NULL)
{
//TODO: error handling...
xp_awk_clrpt (nde);
return XP_NULL;
}
if (!MATCH(awk,TOKEN_COLON)) PANIC (awk, XP_AWK_ECOLON);
@ -1078,10 +1081,27 @@ static xp_awk_nde_t* __parse_basic_expr (xp_awk_t* awk)
n2 = __parse_basic_expr (awk);
if (n2 == XP_NULL)
{
//TODO: error handling
xp_awk_clrpt (nde);
xp_awk_clrpt (n1);
return XP_NULL;
}
// TODO: compose the new node...
tmp = (xp_awk_nde_cnd_t*)xp_malloc(xp_sizeof(xp_awk_nde_cnd_t));
if (tmp == XP_NULL)
{
xp_awk_clrpt (nde);
xp_awk_clrpt (n1);
xp_awk_clrpt (n2);
return XP_NULL;
}
tmp->type = XP_AWK_NDE_CND;
tmp->next = XP_NULL;
tmp->test = nde;
tmp->left = n1;
tmp->right = n2;
nde = (xp_awk_nde_t*)tmp;
}
return nde;

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.44 2006-04-10 15:00:19 bacon Exp $
* $Id: run.c,v 1.45 2006-04-11 09:16:20 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -87,6 +87,7 @@ static xp_awk_val_t* __eval_binop_mod (
static xp_awk_val_t* __eval_unary (xp_awk_t* awk, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_incpre (xp_awk_t* awk, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_incpst (xp_awk_t* awk, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_cnd (xp_awk_t* awk, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_call (xp_awk_t* awk, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_int (xp_awk_t* awk, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_real (xp_awk_t* awk, xp_awk_nde_t* nde);
@ -636,6 +637,7 @@ static xp_awk_val_t* __eval_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
__eval_unary,
__eval_incpre,
__eval_incpst,
__eval_cnd,
__eval_call,
__eval_int,
__eval_real,
@ -1760,6 +1762,24 @@ static xp_awk_val_t* __eval_incpst (xp_awk_t* awk, xp_awk_nde_t* nde)
return res;
}
static xp_awk_val_t* __eval_cnd (xp_awk_t* awk, xp_awk_nde_t* nde)
{
xp_awk_val_t* tv, * v;
xp_awk_nde_cnd_t* cnd = (xp_awk_nde_cnd_t*)nde;
tv = __eval_expression (awk, cnd->test);
if (tv == XP_NULL) return XP_NULL;
xp_awk_refupval (tv);
v = (xp_awk_boolval(tv))?
__eval_expression (awk, cnd->left):
__eval_expression (awk, cnd->right);
xp_awk_refdownval (awk, tv);
return v;
}
static xp_awk_val_t* __eval_call (xp_awk_t* awk, xp_awk_nde_t* nde)
{
xp_awk_func_t* func;

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.c,v 1.32 2006-04-04 16:50:36 bacon Exp $
* $Id: tree.c,v 1.33 2006-04-11 09:16:20 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -119,6 +119,19 @@ static int __print_expression (xp_awk_nde_t* nde)
__incop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
break;
case XP_AWK_NDE_CND:
xp_printf (XP_TEXT("("));
if (__print_expression(((xp_awk_nde_cnd_t*)nde)->test) == -1)
return -1;
xp_printf (XP_TEXT(")?"));
if (__print_expression(((xp_awk_nde_cnd_t*)nde)->left) == -1)
return -1;
xp_printf (XP_TEXT(":"));
if (__print_expression(((xp_awk_nde_cnd_t*)nde)->right) == -1)
return -1;
break;
case XP_AWK_NDE_INT:
#if defined(__LCC__)
xp_printf (XP_TEXT("%lld"), (long long)((xp_awk_nde_int_t*)nde)->val);
@ -547,6 +560,13 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
xp_free (p);
break;
case XP_AWK_NDE_CND:
xp_awk_clrpt (((xp_awk_nde_cnd_t*)p)->test);
xp_awk_clrpt (((xp_awk_nde_cnd_t*)p)->left);
xp_awk_clrpt (((xp_awk_nde_cnd_t*)p)->right);
xp_free (p);
break;
case XP_AWK_NDE_INT:
xp_free (p);
break;

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.h,v 1.30 2006-04-07 16:52:42 bacon Exp $
* $Id: tree.h,v 1.31 2006-04-11 09:16:20 bacon Exp $
*/
#ifndef _XP_AWK_TREE_H_
@ -32,6 +32,7 @@ enum
XP_AWK_NDE_EXP_UNR,
XP_AWK_NDE_EXP_INCPRE,
XP_AWK_NDE_EXP_INCPST,
XP_AWK_NDE_CND,
XP_AWK_NDE_CALL,
XP_AWK_NDE_INT,
XP_AWK_NDE_REAL,
@ -54,6 +55,7 @@ typedef struct xp_awk_nde_t xp_awk_nde_t;
typedef struct xp_awk_nde_blk_t xp_awk_nde_blk_t;
typedef struct xp_awk_nde_ass_t xp_awk_nde_ass_t;
typedef struct xp_awk_nde_exp_t xp_awk_nde_exp_t;
typedef struct xp_awk_nde_cnd_t xp_awk_nde_cnd_t;
typedef struct xp_awk_nde_pos_t xp_awk_nde_pos_t;
typedef struct xp_awk_nde_int_t xp_awk_nde_int_t;
typedef struct xp_awk_nde_real_t xp_awk_nde_real_t;
@ -103,7 +105,7 @@ struct xp_awk_nde_ass_t
};
/* XP_AWK_NDE_EXP_BIN, XP_AWK_NDE_EXP_UNR,
* XP_AWK_NDE_EXP_INCPRE, XP_AWNDE_EXP_INCPST */
* XP_AWK_NDE_EXP_INCPRE, XP_AW_NDE_EXP_INCPST */
struct xp_awk_nde_exp_t
{
XP_AWK_NDE_HDR;
@ -112,6 +114,15 @@ struct xp_awk_nde_exp_t
xp_awk_nde_t* right; /* XP_NULL for UNR, INCPRE, INCPST */
};
/* XP_AWK_NDE_CND */
struct xp_awk_nde_cnd_t
{
XP_AWK_NDE_HDR;
xp_awk_nde_t* test;
xp_awk_nde_t* left;
xp_awk_nde_t* right;
};
/* XP_AWK_NDE_POS - positional - $1, $2, $x, etc */
struct xp_awk_nde_pos_t
{