*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-14 16:26:00 +00:00
parent c09fffb05a
commit eb121cd71c
7 changed files with 76 additions and 23 deletions

View File

@ -3,7 +3,7 @@ OBJS = $(SRCS:.c=.o)
OUT = libxpawk.a OUT = libxpawk.a
CC = cc CC = cc
CFLAGS = -Xc -a ansi -O2 -I../.. -D__STAND_ALONE CFLAGS = -Xc -a ansi -w3 -O2 -I../.. -D__STAND_ALONE
all: $(OBJS) all: $(OBJS)
ar cr $(OUT) $(OBJS) ar cr $(OUT) $(OBJS)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.80 2006-04-14 10:56:42 bacon Exp $ * $Id: parse.c,v 1.81 2006-04-14 16:26:00 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -92,12 +92,6 @@ enum
__TOKEN_COUNT__ __TOKEN_COUNT__
}; };
#if defined(__BORLANDC__) || defined(_MSC_VER)
#define INLINE
#else
#define INLINE inline
#endif
typedef struct __binmap_t __binmap_t; typedef struct __binmap_t __binmap_t;
struct __binmap_t struct __binmap_t
@ -165,6 +159,7 @@ 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);
static int __skip_comment (xp_awk_t* awk); static int __skip_comment (xp_awk_t* awk);
static int __classify_ident (xp_awk_t* awk, const xp_char_t* ident); static int __classify_ident (xp_awk_t* awk, const xp_char_t* ident);
static int __assign_to_opcode (xp_awk_t* awk);
struct __kwent struct __kwent
{ {
@ -230,10 +225,12 @@ do { \
do { if (__get_token(awk) == -1) return -1; } while (0) do { if (__get_token(awk) == -1) return -1; } while (0)
#define MATCH(awk,token_type) ((awk)->token.type == (token_type)) #define MATCH(awk,token_type) ((awk)->token.type == (token_type))
#define CONSUME(awk) \ #define CONSUME(awk) \
do { if (__get_token(awk) == -1) return XP_NULL; } while (0) do { if (__get_token(awk) == -1) return XP_NULL; } while (0)
#define PANIC(awk,code) do { (awk)->errnum = (code); return XP_NULL; } while (0); #define PANIC(awk,code) \
do { (awk)->errnum = (code); return XP_NULL; } while (0)
/* TODO: remove stdio.h */ /* TODO: remove stdio.h */
#ifndef __STAND_ALONE #ifndef __STAND_ALONE
@ -1017,12 +1014,14 @@ static xp_awk_nde_t* __parse_expression (xp_awk_t* awk)
xp_awk_nde_t* x, * y; xp_awk_nde_t* x, * y;
xp_awk_nde_ass_t* nde; xp_awk_nde_ass_t* nde;
int opcode;
x = __parse_basic_expr (awk); x = __parse_basic_expr (awk);
if (x == XP_NULL) return XP_NULL; if (x == XP_NULL) return XP_NULL;
if (!MATCH(awk,TOKEN_ASSIGN)) return x;
/*TODO: PLUS_ASSIGN, MINUS_ASSIGN, .... */ opcode = __assign_to_opcode (awk);
if (opcode == -1) return x;
xp_assert (x->next == XP_NULL); xp_assert (x->next == XP_NULL);
if (x->type != XP_AWK_NDE_ARG && if (x->type != XP_AWK_NDE_ARG &&
x->type != XP_AWK_NDE_ARGIDX && x->type != XP_AWK_NDE_ARGIDX &&
@ -1061,6 +1060,7 @@ static xp_awk_nde_t* __parse_expression (xp_awk_t* awk)
nde->type = XP_AWK_NDE_ASS; nde->type = XP_AWK_NDE_ASS;
nde->next = XP_NULL; nde->next = XP_NULL;
nde->opcode = opcode;
nde->left = x; nde->left = x;
nde->right = y; nde->right = y;
@ -2847,3 +2847,15 @@ static int __classify_ident (xp_awk_t* awk, const xp_char_t* ident)
return TOKEN_IDENT; return TOKEN_IDENT;
} }
static int __assign_to_opcode (xp_awk_t* awk)
{
if (MATCH(awk,TOKEN_ASSIGN)) return XP_AWK_ASSOP_NONE;
if (MATCH(awk,TOKEN_PLUS_ASSIGN)) return XP_AWK_ASSOP_PLUS;
if (MATCH(awk,TOKEN_MINUS_ASSIGN)) return XP_AWK_ASSOP_MINUS;
if (MATCH(awk,TOKEN_MUL_ASSIGN)) return XP_AWK_ASSOP_MUL;
if (MATCH(awk,TOKEN_DIV_ASSIGN)) return XP_AWK_ASSOP_DIV;
if (MATCH(awk,TOKEN_MOD_ASSIGN)) return XP_AWK_ASSOP_MOD;
if (MATCH(awk,TOKEN_EXP_ASSIGN)) return XP_AWK_ASSOP_EXP;
return -1;
}

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.48 2006-04-14 10:56:42 bacon Exp $ * $Id: run.c,v 1.49 2006-04-14 16:26:00 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -680,6 +680,7 @@ static xp_awk_val_t* __eval_assignment (xp_awk_t* awk, xp_awk_nde_t* nde)
val = __eval_expression(awk, ass->right); val = __eval_expression(awk, ass->right);
if (val == XP_NULL) return XP_NULL; if (val == XP_NULL) return XP_NULL;
/*TODO: ass->opcode....*/
return __do_assignment (awk, (xp_awk_nde_var_t*)ass->left, val); return __do_assignment (awk, (xp_awk_nde_var_t*)ass->left, val);
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.h,v 1.8 2006-04-12 03:54:12 bacon Exp $ * $Id: run.h,v 1.9 2006-04-14 16:26:00 bacon Exp $
*/ */
#ifndef _XP_AWK_RUN_H_ #ifndef _XP_AWK_RUN_H_
@ -19,6 +19,18 @@ struct xp_awk_frm_t
xp_awk_frm_t* prev; xp_awk_frm_t* prev;
}; };
enum
{
/* if you change this, you have to change __assop_str in tree.c */
XP_AWK_ASSOP_NONE,
XP_AWK_ASSOP_PLUS,
XP_AWK_ASSOP_MINUS,
XP_AWK_ASSOP_MUL,
XP_AWK_ASSOP_DIV,
XP_AWK_ASSOP_MOD,
XP_AWK_ASSOP_EXP
};
enum enum
{ {
/* if you change this, you have to change /* if you change this, you have to change

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.c,v 1.36 2006-04-14 10:56:42 bacon Exp $ * $Id: tree.c,v 1.37 2006-04-14 16:26:00 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -10,6 +10,17 @@
#include <xp/bas/stdio.h> #include <xp/bas/stdio.h>
#endif #endif
static const xp_char_t* __assop_str[] =
{
XP_TEXT("="),
XP_TEXT("+="),
XP_TEXT("-="),
XP_TEXT("*="),
XP_TEXT("/="),
XP_TEXT("%="),
XP_TEXT("**=")
};
static const xp_char_t* __binop_str[] = static const xp_char_t* __binop_str[] =
{ {
XP_TEXT("||"), XP_TEXT("||"),
@ -37,7 +48,6 @@ static const xp_char_t* __binop_str[] =
XP_TEXT("~"), XP_TEXT("~"),
XP_TEXT("!~") XP_TEXT("!~")
}; };
static const xp_char_t* __unrop_str[] = static const xp_char_t* __unrop_str[] =
@ -72,7 +82,8 @@ static int __print_expression (xp_awk_nde_t* nde)
switch (nde->type) { switch (nde->type) {
case XP_AWK_NDE_ASS: case XP_AWK_NDE_ASS:
if (__print_expression (((xp_awk_nde_ass_t*)nde)->left) == -1) return -1; if (__print_expression (((xp_awk_nde_ass_t*)nde)->left) == -1) return -1;
xp_printf (XP_TEXT(" = ")); xp_printf (XP_TEXT(" %s "),
__assop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
if (__print_expression (((xp_awk_nde_ass_t*)nde)->right) == -1) return -1; if (__print_expression (((xp_awk_nde_ass_t*)nde)->right) == -1) return -1;
xp_assert ((((xp_awk_nde_ass_t*)nde)->right)->next == XP_NULL); xp_assert ((((xp_awk_nde_ass_t*)nde)->right)->next == XP_NULL);
break; break;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.h,v 1.32 2006-04-14 10:56:42 bacon Exp $ * $Id: tree.h,v 1.33 2006-04-14 16:26:00 bacon Exp $
*/ */
#ifndef _XP_AWK_TREE_H_ #ifndef _XP_AWK_TREE_H_
@ -27,6 +27,10 @@ enum
XP_AWK_NDE_NEXTFILE, XP_AWK_NDE_NEXTFILE,
/* expression */ /* expression */
/* if you change the following values including their order,
* you should change __eval_func of __eval_expression
* in run.c accordingly */
XP_AWK_NDE_ASS, XP_AWK_NDE_ASS,
XP_AWK_NDE_EXP_BIN, XP_AWK_NDE_EXP_BIN,
XP_AWK_NDE_EXP_UNR, XP_AWK_NDE_EXP_UNR,
@ -100,6 +104,7 @@ struct xp_awk_nde_blk_t
struct xp_awk_nde_ass_t struct xp_awk_nde_ass_t
{ {
XP_AWK_NDE_HDR; XP_AWK_NDE_HDR;
int opcode;
xp_awk_nde_t* left; xp_awk_nde_t* left;
xp_awk_nde_t* right; xp_awk_nde_t* right;
}; };

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.21 2006-04-14 11:14:58 bacon Exp $ * $Id: awk.c,v 1.22 2006-04-14 16:26:00 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk.h>
@ -90,18 +90,30 @@ int xp_main (int argc, xp_char_t* argv[])
if (xp_awk_parse(awk) == -1) if (xp_awk_parse(awk) == -1)
{ {
#if defined(_SCO_DS) && defined(XP_CHAR_IS_WCHAR)
xp_printf (
XP_TEXT("error: cannot parse program - [%d] %ls\n"),
xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
#else
xp_printf ( xp_printf (
XP_TEXT("error: cannot parse program - [%d] %s\n"), XP_TEXT("error: cannot parse program - [%d] %s\n"),
xp_awk_geterrnum(awk), xp_awk_geterrstr(awk)); xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
#endif
xp_awk_close (awk); xp_awk_close (awk);
return -1; return -1;
} }
if (xp_awk_run(awk) == -1) if (xp_awk_run(awk) == -1)
{ {
#if defined(_SCO_DS) && defined(XP_CHAR_IS_WCHAR)
xp_printf (
XP_TEXT("error: cannot run program - [%d] %ls\n"),
xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
#else
xp_printf ( xp_printf (
XP_TEXT("error: cannot run program - [%d] %s\n"), XP_TEXT("error: cannot run program - [%d] %s\n"),
xp_awk_geterrnum(awk), xp_awk_geterrstr(awk)); xp_awk_geterrnum(awk), xp_awk_geterrstr(awk));
#endif
xp_awk_close (awk); xp_awk_close (awk);
return -1; return -1;
} }