*** empty log message ***

This commit is contained in:
hyung-hwan 2006-06-13 15:11:39 +00:00
parent cb98dbc26f
commit 0a22297056
4 changed files with 87 additions and 25 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.112 2006-06-13 08:35:53 bacon Exp $ * $Id: parse.c,v 1.113 2006-06-13 15:11:39 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -152,7 +152,6 @@ 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_return (xp_awk_t* awk);
static xp_awk_nde_t* __parse_exit (xp_awk_t* awk); static xp_awk_nde_t* __parse_exit (xp_awk_t* awk);
static xp_awk_nde_t* __parse_delete (xp_awk_t* awk); static xp_awk_nde_t* __parse_delete (xp_awk_t* awk);
static xp_awk_nde_t* __parse_getline (xp_awk_t* awk);
static xp_awk_nde_t* __parse_print (xp_awk_t* awk); static xp_awk_nde_t* __parse_print (xp_awk_t* awk);
static xp_awk_nde_t* __parse_printf (xp_awk_t* awk); static xp_awk_nde_t* __parse_printf (xp_awk_t* awk);
static xp_awk_nde_t* __parse_next (xp_awk_t* awk); static xp_awk_nde_t* __parse_next (xp_awk_t* awk);
@ -1500,8 +1499,8 @@ static xp_awk_nde_t* __parse_bitwise_or (xp_awk_t* awk)
nde->type = XP_AWK_NDE_GETLINE; nde->type = XP_AWK_NDE_GETLINE;
nde->next = XP_NULL; nde->next = XP_NULL;
nde->var = var; nde->var = var;
nde->cmd = left; nde->in_type = XP_AWK_GETLINE_PIPE;
nde->in = XP_NULL; nde->in = left;
left = (xp_awk_nde_t*)nde; left = (xp_awk_nde_t*)nde;
} }
@ -1968,7 +1967,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
nde = __parse_expression (awk); nde = __parse_expression (awk);
if (nde == XP_NULL) return XP_NULL; if (nde == XP_NULL) return XP_NULL;
/* ---------------- */ /* parse subsequent expressions separated by a comma, if any */
last = nde; last = nde;
xp_assert (last->next == XP_NULL); xp_assert (last->next == XP_NULL);
@ -1993,7 +1992,7 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
last->next = tmp; last->next = tmp;
last = tmp; last = tmp;
} }
/* ----------------- */ /* ----------------- */
/* check for the closing parenthesis */ /* check for the closing parenthesis */
if (!MATCH(awk,TOKEN_RPAREN)) if (!MATCH(awk,TOKEN_RPAREN))
@ -2008,9 +2007,12 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
return XP_NULL; return XP_NULL;
} }
/* ----------------- */ /* check if it is a chained node */
if (nde->next != XP_NULL) if (nde->next != XP_NULL)
{ {
/* if so, it is a expression group */
/* (expr1, expr2, expr2) */
xp_awk_nde_grp_t* tmp; xp_awk_nde_grp_t* tmp;
if (!MATCH(awk,TOKEN_IN)) if (!MATCH(awk,TOKEN_IN))
@ -2033,10 +2035,60 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
nde = (xp_awk_nde_t*)tmp; nde = (xp_awk_nde_t*)tmp;
} }
/* ----------------- */ /* ----------------- */
return nde; return nde;
} }
else if (MATCH(awk,TOKEN_GETLINE))
{
xp_awk_nde_getline_t* nde;
xp_awk_nde_t* var = XP_NULL;
xp_awk_nde_t* in = XP_NULL;
if (__get_token(awk) == -1) return XP_NULL;
if (MATCH(awk,TOKEN_IDENT))
{
/* getline var */
var = __parse_primary (awk);
if (var == XP_NULL) return XP_NULL;
}
if (MATCH(awk, TOKEN_LT))
{
/* getline [var] < file */
if (__get_token(awk) == -1)
{
if (var != XP_NULL) xp_awk_clrpt (var);
return XP_NULL;
}
in = __parse_expression (awk);
if (in == XP_NULL)
{
if (var != XP_NULL) xp_awk_clrpt (var);
return XP_NULL;
}
}
nde = (xp_awk_nde_getline_t*)
xp_malloc (xp_sizeof(xp_awk_nde_getline_t));
if (nde == XP_NULL)
{
if (var != XP_NULL) xp_awk_clrpt (var);
if (in != XP_NULL) xp_awk_clrpt (in);
PANIC (awk, XP_AWK_ENOMEM);
}
nde->type = XP_AWK_NDE_GETLINE;
nde->next = XP_NULL;
nde->var = var;
nde->in_type = XP_AWK_GETLINE_FILE;
nde->in = in;
return (xp_awk_nde_t*)nde;
}
/* valid expression introducer is expected */ /* valid expression introducer is expected */
PANIC (awk, XP_AWK_EEXPRESSION); PANIC (awk, XP_AWK_EEXPRESSION);
@ -2663,12 +2715,6 @@ static xp_awk_nde_t* __parse_delete (xp_awk_t* awk)
return XP_NULL; return XP_NULL;
} }
static xp_awk_nde_t* __parse_getline (xp_awk_t* awk)
{
/* TODO: implement this... */
return XP_NULL;
}
static xp_awk_nde_t* __parse_print (xp_awk_t* awk) static xp_awk_nde_t* __parse_print (xp_awk_t* awk)
{ {
xp_awk_nde_print_t* nde; xp_awk_nde_print_t* nde;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.94 2006-06-13 08:35:53 bacon Exp $ * $Id: run.c,v 1.95 2006-06-13 15:11:39 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -1490,6 +1490,7 @@ static xp_awk_val_t* __eval_binop_land (
xp_awk_refdownval (run, lv); xp_awk_refdownval (run, lv);
return res; return res;
} }
static xp_awk_val_t* __eval_binop_in ( static xp_awk_val_t* __eval_binop_in (
xp_awk_run_t* run, xp_awk_nde_t* left, xp_awk_nde_t* right) xp_awk_run_t* run, xp_awk_nde_t* left, xp_awk_nde_t* right)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.c,v 1.52 2006-06-13 08:35:53 bacon Exp $ * $Id: tree.c,v 1.53 2006-06-13 15:11:39 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -68,6 +68,12 @@ static const xp_char_t* __incop_str[] =
XP_T("--") XP_T("--")
}; };
static const xp_char_t* __getline_inop_str[] =
{
XP_T("|"),
XP_T("<")
};
static const xp_char_t* __print_outop_str[] = static const xp_char_t* __print_outop_str[] =
{ {
XP_T("|"), XP_T("|"),
@ -344,10 +350,12 @@ static int __print_expression (xp_awk_nde_t* nde)
{ {
/* TODO */ /* TODO */
xp_awk_nde_getline_t* px = (xp_awk_nde_getline_t*)nde; xp_awk_nde_getline_t* px = (xp_awk_nde_getline_t*)nde;
if (px->cmd != XP_NULL) if (px->in != XP_NULL &&
px->in_type == XP_AWK_GETLINE_PIPE)
{ {
__print_expression (px->cmd); __print_expression (px->in);
xp_printf (XP_T(" | ")); xp_printf (XP_T(" %s "),
__getline_inop_str[px->in_type]);
} }
xp_printf (XP_T("getline")); xp_printf (XP_T("getline"));
@ -357,9 +365,11 @@ static int __print_expression (xp_awk_nde_t* nde)
__print_expression (px->var); __print_expression (px->var);
} }
if (px->in != XP_NULL) if (px->in != XP_NULL &&
px->in_type == XP_AWK_GETLINE_FILE)
{ {
xp_printf (XP_T(" < ")); xp_printf (XP_T(" %s "),
__getline_inop_str[px->in_type]);
__print_expression (px->in); __print_expression (px->in);
} }
break; break;
@ -913,7 +923,6 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
xp_awk_nde_getline_t* px = xp_awk_nde_getline_t* px =
(xp_awk_nde_getline_t*)p; (xp_awk_nde_getline_t*)p;
if (px->var != XP_NULL) xp_awk_clrpt (px->var); if (px->var != XP_NULL) xp_awk_clrpt (px->var);
if (px->cmd != XP_NULL) xp_awk_clrpt (px->cmd);
if (px->in != XP_NULL) xp_awk_clrpt (px->in); if (px->in != XP_NULL) xp_awk_clrpt (px->in);
xp_free (p); xp_free (p);
break; break;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.h,v 1.43 2006-06-13 08:35:53 bacon Exp $ * $Id: tree.h,v 1.44 2006-06-13 15:11:39 bacon Exp $
*/ */
#ifndef _XP_AWK_TREE_H_ #ifndef _XP_AWK_TREE_H_
@ -57,6 +57,12 @@ enum
XP_AWK_NDE_PRINT XP_AWK_NDE_PRINT
}; };
enum
{
XP_AWK_GETLINE_PIPE,
XP_AWK_GETLINE_FILE
};
enum enum
{ {
XP_AWK_PRINT_PIPE, XP_AWK_PRINT_PIPE,
@ -215,7 +221,7 @@ struct xp_awk_nde_getline_t
{ {
XP_AWK_NDE_HDR; XP_AWK_NDE_HDR;
xp_awk_nde_t* var; xp_awk_nde_t* var;
xp_awk_nde_t* cmd; int in_type; /* XP_AWK_GETLINE_PIPE, XP_AWK_GETLINE_FILE */
xp_awk_nde_t* in; xp_awk_nde_t* in;
}; };