*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-11 15:44:30 +00:00
parent ff4f09f03f
commit 46a2b28e62
4 changed files with 154 additions and 25 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.77 2006-04-11 09:16:20 bacon Exp $ * $Id: parse.c,v 1.78 2006-04-11 15:44:30 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -17,30 +17,38 @@ enum
TOKEN_EOF, TOKEN_EOF,
TOKEN_ASSIGN, TOKEN_ASSIGN,
TOKEN_PLUS_ASSIGN,
TOKEN_MINUS_ASSIGN,
TOKEN_MUL_ASSIGN,
TOKEN_DIV_ASSIGN,
TOKEN_MOD_ASSIGN,
TOKEN_EXP_ASSIGN,
TOKEN_EQ, TOKEN_EQ,
TOKEN_NE, TOKEN_NE,
TOKEN_LE, TOKEN_LE,
TOKEN_LT, TOKEN_LT,
TOKEN_GE, TOKEN_GE,
TOKEN_GT, TOKEN_GT,
TOKEN_MA, /* match */
TOKEN_NM, /* not match */
TOKEN_NOT, TOKEN_NOT,
TOKEN_PLUS, TOKEN_PLUS,
TOKEN_PLUSPLUS, TOKEN_PLUSPLUS,
TOKEN_PLUS_ASSIGN,
TOKEN_MINUS, TOKEN_MINUS,
TOKEN_MINUSMINUS, TOKEN_MINUSMINUS,
TOKEN_MINUS_ASSIGN,
TOKEN_MUL, TOKEN_MUL,
TOKEN_DIV, TOKEN_DIV,
TOKEN_MOD, TOKEN_MOD,
TOKEN_RSHIFT,
TOKEN_LSHIFT,
TOKEN_LOR, TOKEN_LOR,
TOKEN_LAND, TOKEN_LAND,
TOKEN_BOR, TOKEN_BOR,
TOKEN_BXOR, TOKEN_BXOR,
TOKEN_BAND, TOKEN_BAND,
TOKEN_BNOT, TOKEN_BNOT,
TOKEN_RSHIFT,
TOKEN_LSHIFT,
TOKEN_EXP,
TOKEN_LPAREN, TOKEN_LPAREN,
TOKEN_RPAREN, TOKEN_RPAREN,
@ -80,6 +88,8 @@ enum
TOKEN_LOCAL, TOKEN_LOCAL,
TOKEN_GLOBAL, TOKEN_GLOBAL,
TOKEN_IN,
__TOKEN_COUNT__ __TOKEN_COUNT__
}; };
@ -167,6 +177,7 @@ static struct __kwent __kwtab[] =
{ {
{ XP_TEXT("BEGIN"), TOKEN_BEGIN, 0 }, { XP_TEXT("BEGIN"), TOKEN_BEGIN, 0 },
{ XP_TEXT("END"), TOKEN_END, 0 }, { XP_TEXT("END"), TOKEN_END, 0 },
{ XP_TEXT("function"), TOKEN_FUNCTION, 0 }, { XP_TEXT("function"), TOKEN_FUNCTION, 0 },
{ XP_TEXT("func"), TOKEN_FUNCTION, 0 }, { XP_TEXT("func"), TOKEN_FUNCTION, 0 },
{ XP_TEXT("if"), TOKEN_IF, 0 }, { XP_TEXT("if"), TOKEN_IF, 0 },
@ -185,6 +196,8 @@ static struct __kwent __kwtab[] =
{ XP_TEXT("local"), TOKEN_LOCAL, XP_AWK_EXPLICIT }, { XP_TEXT("local"), TOKEN_LOCAL, XP_AWK_EXPLICIT },
{ XP_TEXT("global"), TOKEN_GLOBAL, XP_AWK_EXPLICIT }, { XP_TEXT("global"), TOKEN_GLOBAL, XP_AWK_EXPLICIT },
{ XP_TEXT("in"), TOKEN_IN, 0 },
{ XP_NULL, 0, 0 } { XP_NULL, 0, 0 }
}; };
@ -1325,6 +1338,7 @@ static xp_awk_nde_t* __parse_multiplicative (xp_awk_t* awk)
{ TOKEN_MUL, XP_AWK_BINOP_MUL }, { TOKEN_MUL, XP_AWK_BINOP_MUL },
{ TOKEN_DIV, XP_AWK_BINOP_DIV }, { TOKEN_DIV, XP_AWK_BINOP_DIV },
{ TOKEN_MOD, XP_AWK_BINOP_MOD }, { TOKEN_MOD, XP_AWK_BINOP_MOD },
{ TOKEN_EXP, XP_AWK_BINOP_EXP },
{ TOKEN_EOF, 0 } { TOKEN_EOF, 0 }
}; };
@ -2297,6 +2311,12 @@ static int __get_token (xp_awk_t* awk)
ADD_TOKEN_STR (awk, XP_TEXT("!=")); ADD_TOKEN_STR (awk, XP_TEXT("!="));
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
} }
else if (c == XP_CHAR('@'))
{
SET_TOKEN_TYPE (awk, TOKEN_NM);
ADD_TOKEN_STR (awk, XP_TEXT("!="));
GET_CHAR_TO (awk, c);
}
else else
{ {
SET_TOKEN_TYPE (awk, TOKEN_NOT); SET_TOKEN_TYPE (awk, TOKEN_NOT);
@ -2360,12 +2380,6 @@ static int __get_token (xp_awk_t* awk)
ADD_TOKEN_STR (awk, XP_TEXT("|")); ADD_TOKEN_STR (awk, XP_TEXT("|"));
} }
} }
else if (c == XP_CHAR('^'))
{
SET_TOKEN_TYPE (awk, TOKEN_BXOR);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c);
}
else if (c == XP_CHAR('&')) else if (c == XP_CHAR('&'))
{ {
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
@ -2387,6 +2401,18 @@ static int __get_token (xp_awk_t* awk)
ADD_TOKEN_CHAR (awk, c); ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
} }
else if (c == XP_CHAR('^'))
{
SET_TOKEN_TYPE (awk, TOKEN_BXOR);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c);
}
else if (c == XP_CHAR('@'))
{
SET_TOKEN_TYPE (awk, TOKEN_MA);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c);
}
else if (c == XP_CHAR('+')) else if (c == XP_CHAR('+'))
{ {
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
@ -2431,23 +2457,67 @@ static int __get_token (xp_awk_t* awk)
} }
else if (c == XP_CHAR('*')) else if (c == XP_CHAR('*'))
{ {
SET_TOKEN_TYPE (awk, TOKEN_MUL);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
if (c == XP_CHAR('='))
{
SET_TOKEN_TYPE (awk, TOKEN_MUL_ASSIGN);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c);
}
else if (c == XP_CHAR('*'))
{
GET_CHAR_TO (awk, c);
if (c == XP_CHAR('='))
{
SET_TOKEN_TYPE (awk, TOKEN_EXP_ASSIGN);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c);
}
else
{
SET_TOKEN_TYPE (awk, TOKEN_EXP);
ADD_TOKEN_CHAR (awk, c);
}
}
else
{
SET_TOKEN_TYPE (awk, TOKEN_MUL);
ADD_TOKEN_CHAR (awk, c);
}
} }
else if (c == XP_CHAR('/')) else if (c == XP_CHAR('/'))
{ {
// TODO: handle regular expression here... /^pattern$/ // TODO: handle regular expression here... /^pattern$/
SET_TOKEN_TYPE (awk, TOKEN_DIV);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
if (c == XP_CHAR('='))
{
SET_TOKEN_TYPE (awk, TOKEN_DIV_ASSIGN);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c);
}
else
{
SET_TOKEN_TYPE (awk, TOKEN_DIV);
ADD_TOKEN_CHAR (awk, c);
}
} }
else if (c == XP_CHAR('%')) else if (c == XP_CHAR('%'))
{ {
SET_TOKEN_TYPE (awk, TOKEN_MOD);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c); GET_CHAR_TO (awk, c);
if (c == XP_CHAR('='))
{
SET_TOKEN_TYPE (awk, TOKEN_MOD_ASSIGN);
ADD_TOKEN_CHAR (awk, c);
GET_CHAR_TO (awk, c);
}
else
{
SET_TOKEN_TYPE (awk, TOKEN_MOD);
ADD_TOKEN_CHAR (awk, c);
}
} }
else if (c == XP_CHAR('(')) else if (c == XP_CHAR('('))
{ {

View File

@ -1,9 +1,12 @@
/* /*
* $Id: run.c,v 1.45 2006-04-11 09:16:20 bacon Exp $ * $Id: run.c,v 1.46 2006-04-11 15:44:30 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
// TODO: remove this dependency...
#include <math.h>
#ifndef __STAND_ALONE #ifndef __STAND_ALONE
#include <xp/bas/assert.h> #include <xp/bas/assert.h>
#include <xp/bas/string.h> #include <xp/bas/string.h>
@ -83,6 +86,8 @@ static xp_awk_val_t* __eval_binop_div (
xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right); xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right);
static xp_awk_val_t* __eval_binop_mod ( static xp_awk_val_t* __eval_binop_mod (
xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right); xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right);
static xp_awk_val_t* __eval_binop_exp (
xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right);
static xp_awk_val_t* __eval_unary (xp_awk_t* awk, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_unary (xp_awk_t* awk, xp_awk_nde_t* nde);
static xp_awk_val_t* __eval_incpre (xp_awk_t* awk, xp_awk_nde_t* nde); static xp_awk_val_t* __eval_incpre (xp_awk_t* awk, xp_awk_nde_t* nde);
@ -228,7 +233,11 @@ int xp_awk_run (xp_awk_t* awk)
while (awk->run.exit_level != EXIT_GLOBAL) while (awk->run.exit_level != EXIT_GLOBAL)
{ {
awk->run.exit_level = EXIT_NONE; awk->run.exit_level = EXIT_NONE;
//
// TODO: execute pattern blocks. // TODO: execute pattern blocks.
//
break; break;
} }
@ -772,7 +781,8 @@ static xp_awk_val_t* __eval_binary (xp_awk_t* awk, xp_awk_nde_t* nde)
__eval_binop_minus, __eval_binop_minus,
__eval_binop_mul, __eval_binop_mul,
__eval_binop_div, __eval_binop_div,
__eval_binop_mod __eval_binop_mod,
__eval_binop_exp
}; };
xp_awk_nde_exp_t* exp = (xp_awk_nde_exp_t*)nde; xp_awk_nde_exp_t* exp = (xp_awk_nde_exp_t*)nde;
xp_awk_val_t* left, * right, * res; xp_awk_val_t* left, * right, * res;
@ -1471,6 +1481,53 @@ static xp_awk_val_t* __eval_binop_mod (
return res; return res;
} }
static xp_awk_val_t* __eval_binop_exp (
xp_awk_t* awk, xp_awk_val_t* left, xp_awk_val_t* right)
{
xp_awk_val_t* res = XP_NULL;
if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_INT)
{
xp_long_t r = 1;
xp_long_t cnt = ((xp_awk_val_int_t*)right)->val;
while (cnt-- > 0) r *= ((xp_awk_val_int_t*)left)->val;
res = xp_awk_makeintval (awk, r);
}
else if (left->type == XP_AWK_VAL_INT &&
right->type == XP_AWK_VAL_REAL)
{
// TODO: write own pow...
double x = ((xp_awk_val_int_t*)left)->val;
double y = ((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, pow (x, y));
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_INT)
{
// TODO: write own pow...
double x = ((xp_awk_val_real_t*)left)->val;
double y = ((xp_awk_val_int_t*)right)->val;
res = xp_awk_makerealval (awk, pow (x, y));
}
else if (left->type == XP_AWK_VAL_REAL &&
right->type == XP_AWK_VAL_REAL)
{
// TODO: wirte own pow...
double x = ((xp_awk_val_real_t*)left)->val;
double y = ((xp_awk_val_real_t*)right)->val;
res = xp_awk_makerealval (awk, pow (x, y));
}
else
{
PANIC (awk, XP_AWK_EOPERAND);
}
if (res == XP_NULL) PANIC (awk, XP_AWK_ENOMEM);
return res;
}
static xp_awk_val_t* __eval_unary (xp_awk_t* awk, xp_awk_nde_t* nde) static xp_awk_val_t* __eval_unary (xp_awk_t* awk, xp_awk_nde_t* nde)
{ {
xp_awk_val_t* left, * res = XP_NULL; xp_awk_val_t* left, * res = XP_NULL;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.h,v 1.6 2006-04-02 12:41:14 bacon Exp $ * $Id: run.h,v 1.7 2006-04-11 15:44:30 bacon Exp $
*/ */
#ifndef _XP_AWK_RUN_H_ #ifndef _XP_AWK_RUN_H_
@ -22,7 +22,7 @@ struct xp_awk_frm_t
enum enum
{ {
/* if you change this, you have to change /* if you change this, you have to change
* __binop_str in tree.c accordingly. */ * __binop_str in tree.c and __binop_func in run.c accordingly. */
XP_AWK_BINOP_LOR, XP_AWK_BINOP_LOR,
XP_AWK_BINOP_LAND, XP_AWK_BINOP_LAND,
XP_AWK_BINOP_BOR, XP_AWK_BINOP_BOR,
@ -43,7 +43,8 @@ enum
XP_AWK_BINOP_MINUS, XP_AWK_BINOP_MINUS,
XP_AWK_BINOP_MUL, XP_AWK_BINOP_MUL,
XP_AWK_BINOP_DIV, XP_AWK_BINOP_DIV,
XP_AWK_BINOP_MOD XP_AWK_BINOP_MOD,
XP_AWK_BINOP_EXP
}; };
enum enum

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.c,v 1.33 2006-04-11 09:16:20 bacon Exp $ * $Id: tree.c,v 1.34 2006-04-11 15:44:30 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -32,7 +32,8 @@ static const xp_char_t* __binop_str[] =
XP_TEXT("-"), XP_TEXT("-"),
XP_TEXT("*"), XP_TEXT("*"),
XP_TEXT("/"), XP_TEXT("/"),
XP_TEXT("%") XP_TEXT("%"),
XP_TEXT("**")
}; };
static const xp_char_t* __unrop_str[] = static const xp_char_t* __unrop_str[] =