diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 73f90915..eccdf434 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.128 2006-06-29 14:38:01 bacon Exp $ + * $Id: parse.c,v 1.129 2006-06-29 15:40:30 bacon Exp $ */ #include @@ -65,12 +65,6 @@ enum TOKEN_COLON, TOKEN_QUEST, - TOKEN_INT, - TOKEN_REAL, - TOKEN_STR, - TOKEN_REX, - - TOKEN_IDENT, TOKEN_BEGIN, TOKEN_END, TOKEN_FUNCTION, @@ -93,6 +87,12 @@ enum TOKEN_LOCAL, TOKEN_GLOBAL, + TOKEN_IDENT, + TOKEN_INT, + TOKEN_REAL, + TOKEN_STR, + TOKEN_REX, + __TOKEN_COUNT__ }; @@ -136,6 +136,7 @@ static xp_awk_nde_t* __parse_bitwise_and (xp_awk_t* awk); static xp_awk_nde_t* __parse_equality (xp_awk_t* awk); static xp_awk_nde_t* __parse_relational (xp_awk_t* awk); static xp_awk_nde_t* __parse_shift (xp_awk_t* awk); +static xp_awk_nde_t* __parse_concat (xp_awk_t* awk); static xp_awk_nde_t* __parse_additive (xp_awk_t* awk); static xp_awk_nde_t* __parse_multiplicative (xp_awk_t* awk); @@ -1127,13 +1128,6 @@ static xp_awk_nde_t* __parse_statement_nb (xp_awk_t* awk) static xp_awk_nde_t* __parse_expression (xp_awk_t* awk) { - /* - * ::= | - * ::= assignmentOperator - * assignmentOperator ::= '=' - * ::= - */ - xp_awk_nde_t* x, * y; xp_awk_nde_ass_t* nde; int opcode; @@ -1622,7 +1616,47 @@ static xp_awk_nde_t* __parse_shift (xp_awk_t* awk) { TOKEN_EOF, 0 } }; - return __parse_binary_expr (awk, map, __parse_additive); + return __parse_binary_expr (awk, map, __parse_concat); +} + +static xp_awk_nde_t* __parse_concat (xp_awk_t* awk) +{ + xp_awk_nde_exp_t* nde; + xp_awk_nde_t* left, * right; + + left = __parse_additive (awk); + if (left == XP_NULL) return XP_NULL; + + /* TODO: write a better code to do this.... + * first of all, is the following check sufficient??? */ + while (awk->token.type > TOKEN_QUEST) + { + right = __parse_additive (awk); + if (right == XP_NULL) + { + xp_awk_clrpt (left); + return XP_NULL; + } + + nde = (xp_awk_nde_exp_t*) + xp_malloc (xp_sizeof(xp_awk_nde_exp_t)); + if (nde == XP_NULL) + { + xp_awk_clrpt (left); + xp_awk_clrpt (right); + PANIC (awk, XP_AWK_ENOMEM); + } + + nde->type = XP_AWK_NDE_EXP_BIN; + nde->next = XP_NULL; + nde->opcode = XP_AWK_BINOP_CONCAT; + nde->left = left; + nde->right = right; + + left = (xp_awk_nde_t*)nde; + } + + return left; } static xp_awk_nde_t* __parse_additive (xp_awk_t* awk) diff --git a/ase/awk/run.c b/ase/awk/run.c index e96d36bf..61093f95 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.114 2006-06-29 14:38:01 bacon Exp $ + * $Id: run.c,v 1.115 2006-06-29 15:40:30 bacon Exp $ */ #include @@ -112,6 +112,8 @@ static xp_awk_val_t* __eval_binop_mod ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right); static xp_awk_val_t* __eval_binop_exp ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right); +static xp_awk_val_t* __eval_binop_concat ( + xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right); static xp_awk_val_t* __eval_binop_ma ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right); static xp_awk_val_t* __eval_binop_nm ( @@ -1514,6 +1516,7 @@ static xp_awk_val_t* __eval_binary (xp_awk_run_t* run, xp_awk_nde_t* nde) __eval_binop_mod, __eval_binop_exp, + __eval_binop_concat, __eval_binop_ma, __eval_binop_nm }; @@ -2336,6 +2339,14 @@ static xp_awk_val_t* __eval_binop_exp ( return res; } +static xp_awk_val_t* __eval_binop_concat ( + xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right) +{ +xp_printf (XP_T("eval_binop_concat not implemented yet...\n")); + PANIC (run, XP_AWK_EINTERNAL); + return XP_NULL; +} + static xp_awk_val_t* __eval_binop_ma ( xp_awk_run_t* run, xp_awk_val_t* left, xp_awk_val_t* right) { diff --git a/ase/awk/run.h b/ase/awk/run.h index 10ae9e3b..53a7d96c 100644 --- a/ase/awk/run.h +++ b/ase/awk/run.h @@ -1,5 +1,5 @@ /* - * $Id: run.h,v 1.13 2006-04-29 12:09:29 bacon Exp $ + * $Id: run.h,v 1.14 2006-06-29 15:40:30 bacon Exp $ */ #ifndef _XP_AWK_RUN_H_ @@ -50,6 +50,7 @@ enum XP_AWK_BINOP_MOD, XP_AWK_BINOP_EXP, + XP_AWK_BINOP_CONCAT, XP_AWK_BINOP_MA, XP_AWK_BINOP_NM }; diff --git a/ase/awk/tree.c b/ase/awk/tree.c index 852c5300..e350dd05 100644 --- a/ase/awk/tree.c +++ b/ase/awk/tree.c @@ -1,5 +1,5 @@ /* - * $Id: tree.c,v 1.60 2006-06-29 14:38:01 bacon Exp $ + * $Id: tree.c,v 1.61 2006-06-29 15:40:30 bacon Exp $ */ #include @@ -48,6 +48,7 @@ static const xp_char_t* __binop_str[] = XP_T("%"), XP_T("**"), + XP_T(" "), XP_T("~"), XP_T("!~") }; diff --git a/ase/test/awk/t12.awk b/ase/test/awk/t12.awk index d9eb2e21..8811ee27 100644 --- a/ase/test/awk/t12.awk +++ b/ase/test/awk/t12.awk @@ -29,4 +29,5 @@ BEGIN getline x < "abc"; print x > "abc"; + print "abc" 1 + 2 3 + 49 2 / 3; }