From 1a01c08001fdef2e6c591fac1cee9a40ab657506 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 29 Apr 2006 12:41:47 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/parse.c | 26 +++++++++++++++++++------- ase/awk/tree.c | 5 +++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 2bd38f5c..e311dbf7 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.95 2006-04-29 12:09:29 bacon Exp $ + * $Id: parse.c,v 1.96 2006-04-29 12:41:47 bacon Exp $ */ #include @@ -162,6 +162,7 @@ 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); +static int __is_plain_var (xp_awk_nde_t* nde); struct __kwent { @@ -1336,10 +1337,7 @@ static xp_awk_nde_t* __parse_in (xp_awk_t* awk) return XP_NULL; } - if (right->type != XP_AWK_NDE_NAMED && - right->type != XP_AWK_NDE_GLOBAL && - right->type != XP_AWK_NDE_LOCAL && - right->type != XP_AWK_NDE_ARG) + if (!__is_plain_var(right)) { xp_awk_clrpt (right); xp_awk_clrpt (left); @@ -2178,11 +2176,17 @@ static xp_awk_nde_t* __parse_for (xp_awk_t* awk) if (MATCH(awk,TOKEN_SEMICOLON)) init = XP_NULL; else { + /* this line is very ugly. it checks the entire next + * expression or the first element in the expression + * is wrapped by a parenthesis */ + int no_foreach = MATCH(awk,TOKEN_LPAREN); + init = __parse_expression (awk); if (init == XP_NULL) return XP_NULL; - if (init->type == XP_AWK_NDE_EXP_BIN && - ((xp_awk_nde_exp_t*)init)->opcode == XP_AWK_BINOP_IN) + if (!no_foreach && init->type == XP_AWK_NDE_EXP_BIN && + ((xp_awk_nde_exp_t*)init)->opcode == XP_AWK_BINOP_IN && + __is_plain_var(((xp_awk_nde_exp_t*)init)->left)) { /* switch to foreach */ @@ -3168,3 +3172,11 @@ static int __assign_to_opcode (xp_awk_t* awk) return -1; } + +static int __is_plain_var (xp_awk_nde_t* nde) +{ + return nde->type == XP_AWK_NDE_GLOBAL || + nde->type == XP_AWK_NDE_LOCAL || + nde->type == XP_AWK_NDE_ARG || + nde->type == XP_AWK_NDE_NAMED; +} diff --git a/ase/awk/tree.c b/ase/awk/tree.c index c9e30e57..c83a343e 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c,v 1.43 2006-04-29 12:09:29 bacon Exp $ + * $Id: tree.c,v 1.44 2006-04-29 12:41:47 bacon Exp $ */ #include @@ -25,6 +25,8 @@ static const xp_char_t* __binop_str[] = { XP_TEXT("||"), XP_TEXT("&&"), + XP_TEXT("in"), + XP_TEXT("|"), XP_TEXT("^"), XP_TEXT("&"), @@ -46,7 +48,6 @@ static const xp_char_t* __binop_str[] = XP_TEXT("%"), XP_TEXT("**"), - XP_TEXT("in"), XP_TEXT("~"), XP_TEXT("!~") };