From af4c825fc4bb167fdd3380ad9d8eb820c0cfce86 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 4 Apr 2006 06:26:56 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/parse.c | 94 ++++++++++++++++++++++++++++++++++++++++++++----- ase/awk/run.c | 68 +++++++++++++++++++++++++++++++++-- ase/awk/sa.h | 4 ++- 3 files changed, 154 insertions(+), 12 deletions(-) diff --git a/ase/awk/parse.c b/ase/awk/parse.c index ebb3f569..020395df 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.68 2006-04-02 12:41:14 bacon Exp $ + * $Id: parse.c,v 1.69 2006-04-04 06:26:56 bacon Exp $ */ #include @@ -143,6 +143,7 @@ static xp_awk_nde_t* __parse_next (xp_awk_t* awk); 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_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); @@ -2164,14 +2165,7 @@ static int __get_token (xp_awk_t* awk) } else if (xp_isdigit(c)) { - /* number */ - do { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - } while (xp_isdigit(c)); - - SET_TOKEN_TYPE (awk, TOKEN_INT); -// TODO: enhance nubmer handling + if (__get_number(awk) == -1) return -1; } else if (xp_isalpha(c) || c == XP_CHAR('_')) { @@ -2443,6 +2437,88 @@ static int __get_token (xp_awk_t* awk) return 0; } +static int __get_number (xp_awk_t* awk) +{ + xp_cint_t c; + + xp_assert (XP_STR_LEN(&awk->token.name) == 0); + SET_TOKEN_TYPE (awk, TOKEN_INT); + + c = awk->lex.curc; + + if (c == XP_CHAR('0')) + { + ADD_TOKEN_CHAR (awk, c); + GET_CHAR_TO (awk, c); + + if (c == XP_CHAR('x') || c == XP_CHAR('X')) + { + /* hexadecimal number */ + do + { + ADD_TOKEN_CHAR (awk, c); + GET_CHAR_TO (awk, c); + } while (xp_isxdigit(c)); + + // TODO: return hexadecimal number... + } + else if (c != '.') + { + /* octal number */ + do + { + ADD_TOKEN_CHAR (awk, c); + GET_CHAR_TO (awk, c); + } while (c >= XP_CHAR('0') || c <= XP_CHAR('7')); + + // TOOD: return octal number + } + } + + while (xp_isdigit(c)) + { + ADD_TOKEN_CHAR (awk, c); + GET_CHAR_TO (awk, c); + } + + if (c == XP_CHAR('.')) + { + /* floating-point number */ + SET_TOKEN_TYPE (awk, TOKEN_REAL); + + ADD_TOKEN_CHAR (awk, c); + GET_CHAR_TO (awk, c); + + while (xp_isdigit(c)) + { + ADD_TOKEN_CHAR (awk, c); + GET_CHAR_TO (awk, c); + } + } + + if (c == XP_CHAR('E') || c == XP_CHAR('e')) + { + SET_TOKEN_TYPE (awk, TOKEN_REAL); + + ADD_TOKEN_CHAR (awk, c); + GET_CHAR_TO (awk, c); + + if (c == XP_CHAR('+') || c == XP_CHAR('-')) + { + ADD_TOKEN_CHAR (awk, c); + GET_CHAR_TO (awk, c); + } + + while (xp_isdigit(c)) + { + 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 23205c84..80c24013 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.33 2006-04-03 15:31:33 bacon Exp $ + * $Id: run.c,v 1.34 2006-04-04 06:26:56 bacon Exp $ */ #include @@ -721,6 +721,10 @@ static xp_awk_val_t* __eval_binop_lor ( res = xp_awk_makeintval (awk, r); // TOOD: error handling } + else + { + /* TODO: trigger error */ + } return res; } @@ -739,6 +743,10 @@ static xp_awk_val_t* __eval_binop_land ( res = xp_awk_makeintval (awk, r); // TOOD: error handling } + else + { + // TODO: trigger error + } return res; } @@ -955,6 +963,34 @@ static xp_awk_val_t* __eval_binop_plus ( res = xp_awk_makeintval (awk, r); // TOOD: error handling } + else if (left->type == XP_AWK_VAL_REAL && + right->type == XP_AWK_VAL_REAL) + { + xp_real_t r = + ((xp_awk_val_real_t*)left)->val + + ((xp_awk_val_real_t*)right)->val; + res = xp_awk_makerealval (awk, r); + } + else if (left->type == XP_AWK_VAL_INT && + right->type == XP_AWK_VAL_REAL) + { + xp_real_t r = + ((xp_awk_val_int_t*)left)->val + + ((xp_awk_val_real_t*)right)->val; + res = xp_awk_makerealval (awk, r); + } + else if (left->type == XP_AWK_VAL_REAL && + right->type == XP_AWK_VAL_INT) + { + xp_real_t r = + ((xp_awk_val_real_t*)left)->val + + ((xp_awk_val_int_t*)right)->val; + res = xp_awk_makerealval (awk, r); + } + else + { + /* TODO: trigger error */ + } return res; } @@ -968,11 +1004,39 @@ static xp_awk_val_t* __eval_binop_minus ( right->type == XP_AWK_VAL_INT) { xp_long_t r = - ((xp_awk_val_int_t*)left)->val - + ((xp_awk_val_int_t*)left)->val - ((xp_awk_val_int_t*)right)->val; res = xp_awk_makeintval (awk, r); // TOOD: error handling } + else if (left->type == XP_AWK_VAL_REAL && + right->type == XP_AWK_VAL_REAL) + { + xp_real_t r = + ((xp_awk_val_real_t*)left)->val - + ((xp_awk_val_real_t*)right)->val; + res = xp_awk_makerealval (awk, r); + } + else if (left->type == XP_AWK_VAL_INT && + right->type == XP_AWK_VAL_REAL) + { + xp_real_t r = + ((xp_awk_val_int_t*)left)->val - + ((xp_awk_val_real_t*)right)->val; + res = xp_awk_makerealval (awk, r); + } + else if (left->type == XP_AWK_VAL_REAL && + right->type == XP_AWK_VAL_INT) + { + xp_real_t r = + ((xp_awk_val_real_t*)left)->val - + ((xp_awk_val_int_t*)right)->val; + res = xp_awk_makerealval (awk, r); + } + else + { + /* TODO: trigger error */ + } return res; } diff --git a/ase/awk/sa.h b/ase/awk/sa.h index d84f78eb..e3829e4d 100644 --- a/ase/awk/sa.h +++ b/ase/awk/sa.h @@ -1,5 +1,5 @@ /* - * $Id: sa.h,v 1.17 2006-03-31 16:35:37 bacon Exp $ + * $Id: sa.h,v 1.18 2006-04-04 06:26:56 bacon Exp $ */ #ifndef _XP_AWK_SA_H_ @@ -37,6 +37,7 @@ #ifdef XP_CHAR_IS_MCHAR #define xp_isdigit isdigit +#define xp_isxdigit isxdigit #define xp_isalpha isalpha #define xp_isalnum isalnum #define xp_isspace isspace @@ -44,6 +45,7 @@ #define xp_tolower tolower #else #define xp_isdigit iswdigit +#define xp_isxdigit iswxdigit #define xp_isalpha iswalpha #define xp_isalnum iswalnum #define xp_isspace iswspace