*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-04 06:26:56 +00:00
parent 99d4a51a3c
commit af4c825fc4
3 changed files with 154 additions and 12 deletions

View File

@ -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 <xp/awk/awk_i.h>
@ -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;

View File

@ -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 <xp/awk/awk_i.h>
@ -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;
}

View File

@ -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