*** empty log message ***
This commit is contained in:
parent
693322acb6
commit
8865e9708d
@ -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 <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -66,7 +66,7 @@ enum
|
|||||||
TOKEN_INT,
|
TOKEN_INT,
|
||||||
TOKEN_REAL,
|
TOKEN_REAL,
|
||||||
TOKEN_STR,
|
TOKEN_STR,
|
||||||
TOKEN_REGEX,
|
TOKEN_REX,
|
||||||
|
|
||||||
TOKEN_IDENT,
|
TOKEN_IDENT,
|
||||||
TOKEN_BEGIN,
|
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_token (xp_awk_t* awk);
|
||||||
static int __get_number (xp_awk_t* awk);
|
static int __get_number (xp_awk_t* awk);
|
||||||
static int __get_string (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 __get_char (xp_awk_t* awk);
|
||||||
static int __unget_char (xp_awk_t* awk, xp_cint_t c);
|
static int __unget_char (xp_awk_t* awk, xp_cint_t c);
|
||||||
static int __skip_spaces (xp_awk_t* awk);
|
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;
|
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))
|
else if (MATCH(awk,TOKEN_DOLLAR))
|
||||||
{
|
{
|
||||||
@ -2792,6 +2821,50 @@ static int __get_string (xp_awk_t* awk)
|
|||||||
return 0;
|
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)
|
static int __get_char (xp_awk_t* awk)
|
||||||
{
|
{
|
||||||
xp_ssize_t n;
|
xp_ssize_t n;
|
||||||
|
@ -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 <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -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_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_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_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_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_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);
|
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 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);
|
static xp_char_t* __val_to_str (xp_awk_val_t* v, int* errnum);
|
||||||
|
|
||||||
|
|
||||||
typedef xp_awk_val_t* (*binop_func_t) (
|
typedef xp_awk_val_t* (*binop_func_t) (
|
||||||
xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right);
|
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);
|
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_int,
|
||||||
__eval_real,
|
__eval_real,
|
||||||
__eval_str,
|
__eval_str,
|
||||||
|
__eval_rex,
|
||||||
__eval_named,
|
__eval_named,
|
||||||
__eval_global,
|
__eval_global,
|
||||||
__eval_local,
|
__eval_local,
|
||||||
@ -1815,9 +1816,26 @@ static xp_awk_val_t* __eval_binop_ma (
|
|||||||
static xp_awk_val_t* __eval_binop_nm (
|
static xp_awk_val_t* __eval_binop_nm (
|
||||||
xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right)
|
xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right)
|
||||||
{
|
{
|
||||||
/* TODO: ... */
|
xp_awk_val_t* res;
|
||||||
PANIC (run, XP_AWK_EINTERNAL);
|
|
||||||
return XP_NULL;
|
// 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)
|
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;
|
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)
|
static xp_awk_val_t* __eval_named (xp_awk_run_t* run, xp_awk_nde_t* nde)
|
||||||
{
|
{
|
||||||
xp_awk_pair_t* pair;
|
xp_awk_pair_t* pair;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user