From 8865e9708dee1e98dd0ea6a98bd75c7e85063240 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 24 Apr 2006 11:22:42 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/parse.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++--- ase/awk/run.c | 35 ++++++++++++++++++--- 2 files changed, 107 insertions(+), 9 deletions(-) diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 0007efca..15046de5 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.87 2006-04-22 16:16:40 bacon Exp $ + * $Id: parse.c,v 1.88 2006-04-24 11:22:42 bacon Exp $ */ #include @@ -66,7 +66,7 @@ enum TOKEN_INT, TOKEN_REAL, TOKEN_STR, - TOKEN_REGEX, + TOKEN_REX, TOKEN_IDENT, TOKEN_BEGIN, @@ -155,6 +155,7 @@ static xp_awk_nde_t* __parse_nextfile (xp_awk_t* awk); static int __get_token (xp_awk_t* awk); static int __get_number (xp_awk_t* awk); static int __get_string (xp_awk_t* awk); +static int __get_regex (xp_awk_t* awk); static int __get_char (xp_awk_t* awk); static int __unget_char (xp_awk_t* awk, xp_cint_t c); static int __skip_spaces (xp_awk_t* awk); @@ -1663,9 +1664,37 @@ static xp_awk_nde_t* __parse_primary (xp_awk_t* awk) return (xp_awk_nde_t*)nde; } - else if (MATCH(awk,TOKEN_REGEX)) + else if (MATCH(awk,TOKEN_DIV)) { - /* TODO: .... */ + xp_awk_nde_str_t* nde; + + /* the regular expression is tokenized because of + * context-sensitivity of the slash symbol */ + SET_TOKEN_TYPE (awk, TOKEN_REX); + if (__get_regex(awk) == -1) return XP_NULL; + xp_assert (MATCH(awk,TOKEN_REX)); + + nde = (xp_awk_nde_str_t*)xp_malloc(xp_sizeof(xp_awk_nde_rex_t)); + if (nde == XP_NULL) PANIC (awk, XP_AWK_ENOMEM); + + nde->type = XP_AWK_NDE_REX; + nde->next = XP_NULL; + nde->len = XP_STR_LEN(&awk->token.name); + nde->buf = xp_strxdup(XP_STR_BUF(&awk->token.name), nde->len); + if (nde->buf == XP_NULL) + { + xp_free (nde); + PANIC (awk, XP_AWK_ENOMEM); + } + + if (__get_token(awk) == -1) + { + xp_free (nde->buf); + xp_free (nde); + return XP_NULL; + } + + return (xp_awk_nde_t*)nde; } else if (MATCH(awk,TOKEN_DOLLAR)) { @@ -2792,6 +2821,50 @@ static int __get_string (xp_awk_t* awk) return 0; } +static int __get_regex (xp_awk_t* awk) +{ + /* do proper regular expression parsing */ + xp_cint_t c; + xp_bool_t escaped = xp_false; + + GET_CHAR_TO (awk, c); + while (1) + { + if (c == XP_CHAR_EOF) + { + awk->errnum = XP_AWK_EENDSTR; + return -1; + } + + if (escaped == xp_false && c == XP_CHAR('/')) + { + GET_CHAR_TO (awk, c); + break; + } + + if (escaped == xp_false && c == XP_CHAR('\\')) + { + GET_CHAR_TO (awk, c); + escaped = xp_true; + continue; + } + + if (escaped == xp_true) + { + if (c == XP_CHAR('n')) c = XP_CHAR('\n'); + else if (c == XP_CHAR('r')) c = XP_CHAR('\r'); + else if (c == XP_CHAR('t')) c = XP_CHAR('\t'); + /* TODO: more escape characters */ + escaped = xp_false; + } + + ADD_TOKEN_CHAR (awk, c); + GET_CHAR_TO (awk, c); + } + + return 0; +} + static int __get_char (xp_awk_t* awk) { xp_ssize_t n; diff --git a/ase/awk/run.c b/ase/awk/run.c index a26524cc..987acff4 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.69 2006-04-22 16:16:40 bacon Exp $ + * $Id: run.c,v 1.70 2006-04-24 11:22:42 bacon Exp $ */ #include @@ -116,6 +116,7 @@ static xp_awk_val_t* __eval_call (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_int (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_real (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_str (xp_awk_run_t* run, xp_awk_nde_t* nde); +static xp_awk_val_t* __eval_rex (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_named (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_global (xp_awk_run_t* run, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_local (xp_awk_run_t* run, xp_awk_nde_t* nde); @@ -134,7 +135,6 @@ static int __read_text_input (xp_awk_run_t* run); static int __val_to_num (xp_awk_val_t* v, xp_long_t* l, xp_real_t* r); static xp_char_t* __val_to_str (xp_awk_val_t* v, int* errnum); - typedef xp_awk_val_t* (*binop_func_t) ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right); typedef xp_awk_val_t* (*eval_expr_t) (xp_awk_run_t* run, xp_awk_nde_t* nde); @@ -843,6 +843,7 @@ static xp_awk_val_t* __eval_expression (xp_awk_run_t* run, xp_awk_nde_t* nde) __eval_int, __eval_real, __eval_str, + __eval_rex, __eval_named, __eval_global, __eval_local, @@ -1815,9 +1816,26 @@ static xp_awk_val_t* __eval_binop_ma ( static xp_awk_val_t* __eval_binop_nm ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right) { - /* TODO: ... */ - PANIC (run, XP_AWK_EINTERNAL); - return XP_NULL; + xp_awk_val_t* res; + +// TODO::::: + if (left->type == XP_AWK_VAL_REX && + right->type == XP_AWK_VAL_STR) + { +res = xp_awk_val_nil; + } + else if (left->type == XP_AWK_VAL_STR && + right->type == XP_AWK_VAL_REX) + { +res = xp_awk_val_nil; + } + else + { + PANIC (run, XP_AWK_EOPERAND); + } + + if (res == XP_NULL) PANIC (run, XP_AWK_ENOMEM); + return res; } static xp_awk_val_t* __eval_unary (xp_awk_run_t* run, xp_awk_nde_t* nde) @@ -2364,6 +2382,13 @@ static xp_awk_val_t* __eval_str (xp_awk_run_t* run, xp_awk_nde_t* nde) return val; } +static xp_awk_val_t* __eval_rex (xp_awk_run_t* run, xp_awk_nde_t* nde) +{ +/* TODO */ + PANIC (run, XP_AWK_EINTERNAL); + return XP_NULL; +} + static xp_awk_val_t* __eval_named (xp_awk_run_t* run, xp_awk_nde_t* nde) { xp_awk_pair_t* pair;