diff --git a/ase/awk/makefile.sco b/ase/awk/makefile.sco index 6729a81b..16a83d6d 100644 --- a/ase/awk/makefile.sco +++ b/ase/awk/makefile.sco @@ -3,7 +3,7 @@ OBJS = $(SRCS:.c=.o) OUT = libxpawk.a CC = cc -CFLAGS = -Xc -a ansi -O2 -I../.. -D__STAND_ALONE +CFLAGS = -Xc -a ansi -w3 -O2 -I../.. -D__STAND_ALONE all: $(OBJS) ar cr $(OUT) $(OBJS) diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 8c743988..f2d0ab2c 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -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 @@ -92,12 +92,6 @@ enum __TOKEN_COUNT__ }; -#if defined(__BORLANDC__) || defined(_MSC_VER) - #define INLINE -#else - #define INLINE inline -#endif - typedef struct __binmap_t __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_comment (xp_awk_t* awk); static int __classify_ident (xp_awk_t* awk, const xp_char_t* ident); +static int __assign_to_opcode (xp_awk_t* awk); struct __kwent { @@ -227,13 +222,15 @@ do { \ } while (0) #define GET_TOKEN(awk) \ - 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 CONSUME(awk) \ - 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 CONSUME(awk) \ + do { if (__get_token(awk) == -1) return XP_NULL; } while (0) + +#define PANIC(awk,code) \ + do { (awk)->errnum = (code); return XP_NULL; } while (0) /* TODO: remove stdio.h */ #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_ass_t* nde; + int opcode; x = __parse_basic_expr (awk); 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); if (x->type != XP_AWK_NDE_ARG && 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->next = XP_NULL; + nde->opcode = opcode; nde->left = x; nde->right = y; @@ -2847,3 +2847,15 @@ static int __classify_ident (xp_awk_t* awk, const xp_char_t* 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; +} diff --git a/ase/awk/run.c b/ase/awk/run.c index ccc03907..e28deef9 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -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 @@ -30,9 +30,9 @@ #define EXIT_GLOBAL 4 #define PANIC(awk,code) \ - do { (awk)->errnum = (code); return XP_NULL; } while (0) + do { (awk)->errnum = (code); return XP_NULL; } while (0) #define PANIC_I(awk,code) \ - do { (awk)->errnum = (code); return -1; } while (0) + do { (awk)->errnum = (code); return -1; } while (0) static int __run_block (xp_awk_t* awk, xp_awk_nde_blk_t* nde); static int __run_statement (xp_awk_t* awk, xp_awk_nde_t* nde); @@ -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); if (val == XP_NULL) return XP_NULL; +/*TODO: ass->opcode....*/ return __do_assignment (awk, (xp_awk_nde_var_t*)ass->left, val); } diff --git a/ase/awk/run.h b/ase/awk/run.h index caeda55c..afd6b3ce 100644 --- a/ase/awk/run.h +++ b/ase/awk/run.h @@ -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_ @@ -19,6 +19,18 @@ struct xp_awk_frm_t 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 { /* if you change this, you have to change diff --git a/ase/awk/tree.c b/ase/awk/tree.c index bbaf311d..ebf32be0 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -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 @@ -10,6 +10,17 @@ #include #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[] = { XP_TEXT("||"), @@ -37,7 +48,6 @@ static const xp_char_t* __binop_str[] = XP_TEXT("~"), XP_TEXT("!~") - }; static const xp_char_t* __unrop_str[] = @@ -72,7 +82,8 @@ static int __print_expression (xp_awk_nde_t* nde) switch (nde->type) { case XP_AWK_NDE_ASS: 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; xp_assert ((((xp_awk_nde_ass_t*)nde)->right)->next == XP_NULL); break; diff --git a/ase/awk/tree.h b/ase/awk/tree.h index 31c1f0d2..223363b7 100644 --- a/ase/awk/tree.h +++ b/ase/awk/tree.h @@ -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_ @@ -27,6 +27,10 @@ enum XP_AWK_NDE_NEXTFILE, /* 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_EXP_BIN, XP_AWK_NDE_EXP_UNR, @@ -100,6 +104,7 @@ struct xp_awk_nde_blk_t struct xp_awk_nde_ass_t { XP_AWK_NDE_HDR; + int opcode; xp_awk_nde_t* left; xp_awk_nde_t* right; }; diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index 2b58b7a8..aad8fa9d 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -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 @@ -90,18 +90,30 @@ int xp_main (int argc, xp_char_t* argv[]) 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_TEXT("error: cannot parse program - [%d] %s\n"), xp_awk_geterrnum(awk), xp_awk_geterrstr(awk)); +#endif xp_awk_close (awk); return -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_TEXT("error: cannot run program - [%d] %s\n"), xp_awk_geterrnum(awk), xp_awk_geterrstr(awk)); +#endif xp_awk_close (awk); return -1; }