*** empty log message ***
This commit is contained in:
parent
fa776e0098
commit
29bb43c1e5
@ -1,17 +1,17 @@
|
||||
LIBRARY "xpawk.dll"
|
||||
|
||||
EXPORTS
|
||||
xp_awk_open PRIVATE
|
||||
xp_awk_close PRIVATE
|
||||
xp_awk_open
|
||||
xp_awk_close
|
||||
|
||||
xp_awk_geterrnum PRIVATE
|
||||
xp_awk_geterrstr PRIVATE
|
||||
xp_awk_geterrnum
|
||||
xp_awk_geterrstr
|
||||
|
||||
xp_awk_clear PRIVATE
|
||||
xp_awk_setparseopt PRIVATE
|
||||
xp_awk_clear
|
||||
xp_awk_setparseopt
|
||||
|
||||
xp_awk_attsrc PRIVATE
|
||||
xp_awk_detsrc PRIVATE
|
||||
xp_awk_attsrc
|
||||
xp_awk_detsrc
|
||||
|
||||
xp_awk_parse PRIVATE
|
||||
xp_awk_run PRIVATE
|
||||
xp_awk_parse
|
||||
xp_awk_run
|
||||
|
@ -149,10 +149,6 @@ SOURCE=.\awk_i.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\err.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\map.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h,v 1.39 2006-03-31 16:35:37 bacon Exp $
|
||||
* $Id: awk.h,v 1.40 2006-04-02 12:41:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_AWK_AWK_H_
|
||||
@ -31,6 +31,41 @@ enum
|
||||
XP_AWK_SHIFT = (1 << 4) /* support shift operators */
|
||||
};
|
||||
|
||||
/* error code */
|
||||
enum
|
||||
{
|
||||
XP_AWK_ENOERR, /* no error */
|
||||
XP_AWK_ENOMEM, /* out of memory */
|
||||
|
||||
XP_AWK_ESRCOP,
|
||||
XP_AWK_ESRCCL,
|
||||
XP_AWK_ESRCDT, /* error in reading source */
|
||||
|
||||
XP_AWK_ELXCHR, /* lexer came accross an wrong character */
|
||||
XP_AWK_ELXUNG, /* lexer failed to unget a character */
|
||||
|
||||
XP_AWK_EENDSRC, /* unexpected end of source */
|
||||
XP_AWK_ELBRACE, /* left brace expected */
|
||||
XP_AWK_ELPAREN, /* left parenthesis expected */
|
||||
XP_AWK_ERPAREN, /* right parenthesis expected */
|
||||
XP_AWK_ERBRACK, /* right bracket expected */
|
||||
XP_AWK_ECOMMA, /* comma expected */
|
||||
XP_AWK_ESEMICOLON, /* semicolon expected */
|
||||
XP_AWK_EEXPRESSION, /* expression expected */
|
||||
|
||||
XP_AWK_EWHILE, /* keyword 'while' is expected */
|
||||
XP_AWK_EASSIGNMENT, /* assignment statement expected */
|
||||
XP_AWK_EIDENT, /* identifier expected */
|
||||
XP_AWK_EDUPBEGIN, /* duplicate BEGIN */
|
||||
XP_AWK_EDUPEND, /* duplicate END */
|
||||
XP_AWK_EDUPFUNC, /* duplicate function name */
|
||||
XP_AWK_EDUPPARAM, /* duplicate parameter name */
|
||||
XP_AWK_EDUPVAR, /* duplicate variable name */
|
||||
XP_AWK_EDUPNAME, /* duplicate name - function, variable, etc */
|
||||
XP_AWK_EUNDEF, /* undefined identifier */
|
||||
XP_AWK_ELVALUE /* l-value required */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -1,12 +1,11 @@
|
||||
/*
|
||||
* $Id: awk_i.h,v 1.1 2006-03-31 16:35:37 bacon Exp $
|
||||
* $Id: awk_i.h,v 1.2 2006-04-02 12:41:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_AWK_AWKI_H_
|
||||
#define _XP_AWK_AWKI_H_
|
||||
|
||||
#include <xp/awk/awk.h>
|
||||
#include <xp/awk/err.h>
|
||||
#include <xp/awk/tree.h>
|
||||
#include <xp/awk/tab.h>
|
||||
#include <xp/awk/map.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: err.c,v 1.2 2006-03-31 16:35:37 bacon Exp $
|
||||
* $Id: err.c,v 1.3 2006-04-02 12:41:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -37,7 +37,8 @@ const xp_char_t* xp_awk_geterrstr (xp_awk_t* awk)
|
||||
XP_TEXT("duplicate parameter name"),
|
||||
XP_TEXT("duplicate variable name"),
|
||||
XP_TEXT("duplicate name"),
|
||||
XP_TEXT("undefined identifier")
|
||||
XP_TEXT("undefined identifier"),
|
||||
XP_TEXT("l-value required")
|
||||
};
|
||||
|
||||
if (awk->errnum >= 0 && awk->errnum < xp_countof(__errstr)) {
|
||||
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* $Id: err.h,v 1.2 2006-03-04 15:54:37 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_AWK_ERR_H_
|
||||
#define _XP_AWK_ERR_H_
|
||||
|
||||
#ifndef _XP_AWK_AWK_H_
|
||||
#error Never include this file directly. Include <xp/awk/awk.h> instead
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
XP_AWK_ENOERR, /* no error */
|
||||
XP_AWK_ENOMEM, /* out of memory */
|
||||
|
||||
XP_AWK_ESRCOP,
|
||||
XP_AWK_ESRCCL,
|
||||
XP_AWK_ESRCDT, /* error in reading source */
|
||||
|
||||
XP_AWK_ELXCHR, /* lexer came accross an wrong character */
|
||||
XP_AWK_ELXUNG, /* lexer failed to unget a character */
|
||||
|
||||
XP_AWK_EENDSRC, /* unexpected end of source */
|
||||
XP_AWK_ELBRACE, /* left brace expected */
|
||||
XP_AWK_ELPAREN, /* left parenthesis expected */
|
||||
XP_AWK_ERPAREN, /* right parenthesis expected */
|
||||
XP_AWK_ERBRACK, /* right bracket expected */
|
||||
XP_AWK_ECOMMA, /* comma expected */
|
||||
XP_AWK_ESEMICOLON, /* semicolon expected */
|
||||
XP_AWK_EEXPRESSION, /* expression expected */
|
||||
|
||||
XP_AWK_EWHILE, /* keyword 'while' is expected */
|
||||
XP_AWK_EASSIGNMENT, /* assignment statement expected */
|
||||
XP_AWK_EIDENT, /* identifier expected */
|
||||
XP_AWK_EDUPBEGIN, /* duplicate BEGIN */
|
||||
XP_AWK_EDUPEND, /* duplicate END */
|
||||
XP_AWK_EDUPFUNC, /* duplicate function name */
|
||||
XP_AWK_EDUPPARAM, /* duplicate parameter name */
|
||||
XP_AWK_EDUPVAR, /* duplicate variable name */
|
||||
XP_AWK_EDUPNAME, /* duplicate name - function, variable, etc */
|
||||
XP_AWK_EUNDEF /* undefined identifier */
|
||||
};
|
||||
|
||||
#endif
|
179
ase/awk/parse.c
179
ase/awk/parse.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.c,v 1.67 2006-03-31 16:35:37 bacon Exp $
|
||||
* $Id: parse.c,v 1.68 2006-04-02 12:41:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -126,6 +126,7 @@ static xp_awk_nde_t* __parse_shift (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);
|
||||
static xp_awk_nde_t* __parse_unary (xp_awk_t* awk);
|
||||
static xp_awk_nde_t* __parse_increment (xp_awk_t* awk);
|
||||
static xp_awk_nde_t* __parse_primary (xp_awk_t* awk);
|
||||
static xp_awk_nde_t* __parse_hashidx (xp_awk_t* awk, xp_char_t* name);
|
||||
static xp_awk_nde_t* __parse_funcall (xp_awk_t* awk, xp_char_t* name);
|
||||
@ -1262,98 +1263,100 @@ static xp_awk_nde_t* __parse_multiplicative (xp_awk_t* awk)
|
||||
};
|
||||
|
||||
return __parse_binary_expr (awk, map, __parse_unary);
|
||||
#if 0
|
||||
xp_awk_nde_exp_t* nde;
|
||||
xp_awk_nde_t* left, * right;
|
||||
int opcode;
|
||||
|
||||
left = __parse_unary (awk);
|
||||
if (left == XP_NULL) return XP_NULL;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (MATCH(awk,TOKEN_MUL)) opcode = XP_AWK_BINOP_MUL;
|
||||
else if (MATCH(awk,TOKEN_DIV)) opcode = XP_AWK_BINOP_DIV;
|
||||
else if (MATCH(awk,TOKEN_MOD)) opcode = XP_AWK_BINOP_MOD;
|
||||
else break;
|
||||
|
||||
if (__get_token(awk) == -1)
|
||||
{
|
||||
xp_awk_clrpt (left);
|
||||
return XP_NULL;
|
||||
}
|
||||
|
||||
right = __parse_unary (awk);
|
||||
if (right == XP_NULL)
|
||||
{
|
||||
xp_awk_clrpt (left);
|
||||
return XP_NULL;
|
||||
}
|
||||
|
||||
/* TODO: enhance constant folding. do it in a better way */
|
||||
/* TODO: differentiate different types of numbers ... */
|
||||
if (left->type == XP_AWK_NDE_INT &&
|
||||
right->type == XP_AWK_NDE_INT)
|
||||
{
|
||||
xp_long_t l, r;
|
||||
|
||||
l = ((xp_awk_nde_int_t*)left)->val;
|
||||
r = ((xp_awk_nde_int_t*)right)->val;
|
||||
|
||||
xp_awk_clrpt (right);
|
||||
|
||||
if (opcode == XP_AWK_BINOP_MUL) l *= r;
|
||||
else if (opcode == XP_AWK_BINOP_DIV) l /= r;
|
||||
else if (opcode == XP_AWK_BINOP_MOD) l %= r;
|
||||
|
||||
((xp_awk_nde_int_t*)left)->val = l;
|
||||
continue;
|
||||
}
|
||||
/* TODO:
|
||||
else if (left->type == XP_AWK_NDE_REAL &&
|
||||
right->type == XP_AWK_NDE_REAL)
|
||||
{
|
||||
}
|
||||
else if (left->type == XP_AWK_NDE_STR &&
|
||||
right->type == XP_AWK_NDE_STR)
|
||||
{
|
||||
// TODO: string concatenation operator....
|
||||
}
|
||||
*/
|
||||
|
||||
nde = (xp_awk_nde_exp_t*)xp_malloc(xp_sizeof(xp_awk_nde_exp_t));
|
||||
if (nde == XP_NULL)
|
||||
{
|
||||
xp_awk_clrpt (right);
|
||||
xp_awk_clrpt (left);
|
||||
PANIC (awk, XP_AWK_ENOMEM);
|
||||
}
|
||||
|
||||
nde->type = XP_AWK_NDE_EXP_BIN;
|
||||
nde->next = XP_NULL;
|
||||
nde->opcode = opcode;
|
||||
nde->left = left;
|
||||
nde->right = right;
|
||||
|
||||
left = (xp_awk_nde_t*)nde;
|
||||
}
|
||||
|
||||
return left;
|
||||
#endif
|
||||
}
|
||||
|
||||
static xp_awk_nde_t* __parse_unary (xp_awk_t* awk)
|
||||
{
|
||||
// TOKEN_PLUS_PLUS, TOKEN_MINUS_MINUS
|
||||
//TODO:
|
||||
/*
|
||||
while (MATCH(awk,TOKEN_PLUS) || MATCH(awk,TOKEN_MINUS) ||
|
||||
MATCH(awk,TOKEN_NOT) || MATCH(awk,TOKEN_BNOT))
|
||||
{
|
||||
}
|
||||
*/
|
||||
xp_awk_nde_exp_t* nde;
|
||||
xp_awk_nde_t* left;
|
||||
int opcode;
|
||||
|
||||
return __parse_primary (awk);
|
||||
opcode = (MATCH(awk,TOKEN_PLUS))? XP_AWK_UNROP_PLUS:
|
||||
(MATCH(awk,TOKEN_MINUS))? XP_AWK_UNROP_MINUS:
|
||||
(MATCH(awk,TOKEN_NOT))? XP_AWK_UNROP_NOT:
|
||||
(MATCH(awk,TOKEN_BNOT))? XP_AWK_UNROP_BNOT: -1;
|
||||
|
||||
if (opcode == -1) return __parse_increment (awk);
|
||||
|
||||
if (__get_token(awk) == -1) return XP_NULL;
|
||||
|
||||
left = __parse_unary (awk);
|
||||
if (left == XP_NULL) 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);
|
||||
PANIC (awk, XP_AWK_ENOMEM);
|
||||
}
|
||||
|
||||
nde->type = XP_AWK_NDE_EXP_UNR;
|
||||
nde->next = XP_NULL;
|
||||
nde->opcode = opcode;
|
||||
nde->left = left;
|
||||
nde->right = XP_NULL;
|
||||
|
||||
return (xp_awk_nde_t*)nde;
|
||||
}
|
||||
|
||||
static xp_awk_nde_t* __parse_increment (xp_awk_t* awk)
|
||||
{
|
||||
xp_awk_nde_exp_t* nde;
|
||||
xp_awk_nde_t* left;
|
||||
int type, opcode, opcode1, opcode2;
|
||||
|
||||
opcode1 = MATCH(awk,TOKEN_PLUSPLUS)? XP_AWK_INCOP_PLUS:
|
||||
MATCH(awk,TOKEN_MINUSMINUS)? XP_AWK_INCOP_MINUS: -1;
|
||||
|
||||
if (opcode1 != -1)
|
||||
{
|
||||
if (__get_token(awk) == -1) return XP_NULL;
|
||||
}
|
||||
|
||||
left = __parse_primary (awk);
|
||||
if (left == XP_NULL) return XP_NULL;
|
||||
|
||||
opcode2 = MATCH(awk,TOKEN_PLUSPLUS)? XP_AWK_INCOP_PLUS:
|
||||
MATCH(awk,TOKEN_MINUSMINUS)? XP_AWK_INCOP_MINUS: -1;
|
||||
|
||||
if (opcode1 != -1 && opcode2 != -1)
|
||||
{
|
||||
xp_awk_clrpt (left);
|
||||
PANIC (awk, XP_AWK_ELVALUE);
|
||||
}
|
||||
else if (opcode1 == -1 && opcode2 == -1)
|
||||
{
|
||||
return left;
|
||||
}
|
||||
else if (opcode1 != -1)
|
||||
{
|
||||
type = XP_AWK_NDE_EXP_INCPRE;
|
||||
opcode = opcode1;
|
||||
}
|
||||
else if (opcode2 != -1)
|
||||
{
|
||||
type = XP_AWK_NDE_EXP_INCPST;
|
||||
opcode = opcode2;
|
||||
|
||||
if (__get_token(awk) == -1) 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);
|
||||
PANIC (awk, XP_AWK_ENOMEM);
|
||||
}
|
||||
|
||||
nde->type = type;
|
||||
nde->next = XP_NULL;
|
||||
nde->opcode = opcode;
|
||||
nde->left = left;
|
||||
nde->right = XP_NULL;
|
||||
|
||||
return (xp_awk_nde_t*)nde;
|
||||
}
|
||||
|
||||
static xp_awk_nde_t* __parse_primary (xp_awk_t* awk)
|
||||
|
230
ase/awk/run.c
230
ase/awk/run.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c,v 1.28 2006-03-31 16:35:37 bacon Exp $
|
||||
* $Id: run.c,v 1.29 2006-04-02 12:41:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -39,6 +39,9 @@ static int __run_exit_statement (xp_awk_t* awk, xp_awk_nde_exit_t* nde);
|
||||
static xp_awk_val_t* __eval_expression (xp_awk_t* awk, xp_awk_nde_t* nde);
|
||||
static xp_awk_val_t* __eval_assignment (xp_awk_t* awk, xp_awk_nde_ass_t* nde);
|
||||
static xp_awk_val_t* __eval_binary (xp_awk_t* awk, xp_awk_nde_exp_t* nde);
|
||||
static xp_awk_val_t* __eval_unary (xp_awk_t* awk, xp_awk_nde_exp_t* nde);
|
||||
static xp_awk_val_t* __eval_incpre (xp_awk_t* awk, xp_awk_nde_exp_t* nde);
|
||||
static xp_awk_val_t* __eval_incpst (xp_awk_t* awk, xp_awk_nde_exp_t* nde);
|
||||
static xp_awk_val_t* __eval_funccall (xp_awk_t* awk, xp_awk_nde_call_t* nde);
|
||||
|
||||
static int __raw_push (xp_awk_t* awk, void* val);
|
||||
@ -426,29 +429,39 @@ static xp_awk_val_t* __eval_expression (xp_awk_t* awk, xp_awk_nde_t* nde)
|
||||
switch (nde->type)
|
||||
{
|
||||
case XP_AWK_NDE_ASS:
|
||||
val = __eval_assignment(awk,(xp_awk_nde_ass_t*)nde);
|
||||
val = __eval_assignment (awk, (xp_awk_nde_ass_t*)nde);
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_EXP_BIN:
|
||||
val = __eval_binary(awk,(xp_awk_nde_exp_t*)nde);
|
||||
val = __eval_binary (awk, (xp_awk_nde_exp_t*)nde);
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_EXP_UNR:
|
||||
// TODO: .......................
|
||||
val = __eval_unary (awk, (xp_awk_nde_exp_t*)nde);
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_EXP_INCPRE:
|
||||
val = __eval_incpre (awk, (xp_awk_nde_exp_t*)nde);
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_EXP_INCPST:
|
||||
val = __eval_incpst (awk, (xp_awk_nde_exp_t*)nde);
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_STR:
|
||||
val = xp_awk_makestrval(
|
||||
val = xp_awk_makestrval (
|
||||
((xp_awk_nde_str_t*)nde)->buf,
|
||||
((xp_awk_nde_str_t*)nde)->len);
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_INT:
|
||||
val = xp_awk_makeintval(awk,((xp_awk_nde_int_t*)nde)->val);
|
||||
val = xp_awk_makeintval (
|
||||
awk, ((xp_awk_nde_int_t*)nde)->val);
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_REAL:
|
||||
val = xp_awk_makerealval(awk,((xp_awk_nde_real_t*)nde)->val);
|
||||
val = xp_awk_makerealval (
|
||||
awk, ((xp_awk_nde_real_t*)nde)->val);
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_NAMED:
|
||||
@ -682,13 +695,214 @@ static xp_awk_val_t* __eval_binary (xp_awk_t* awk, xp_awk_nde_exp_t* nde)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xp_awk_refdownval (awk, left);
|
||||
xp_awk_refdownval (awk, right);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static xp_awk_val_t* __eval_unary (xp_awk_t* awk, xp_awk_nde_exp_t* nde)
|
||||
{
|
||||
xp_awk_val_t* left, * res;
|
||||
|
||||
xp_assert (nde->type == XP_AWK_NDE_EXP_UNR);
|
||||
xp_assert (nde->right == XP_NULL);
|
||||
|
||||
left = __eval_expression (awk, nde->left);
|
||||
if (left == XP_NULL) return XP_NULL;
|
||||
|
||||
xp_awk_refupval (left);
|
||||
|
||||
// TODO: a lot of things to do....
|
||||
if (nde->opcode == XP_AWK_UNROP_PLUS)
|
||||
{
|
||||
if (left->type == XP_AWK_VAL_INT)
|
||||
{
|
||||
xp_long_t r = ((xp_awk_val_int_t*)left)->val;
|
||||
res = xp_awk_makeintval (awk, r);
|
||||
}
|
||||
else if (left->type == XP_AWK_VAL_REAL)
|
||||
{
|
||||
xp_real_t r = ((xp_awk_val_real_t*)left)->val;
|
||||
res = xp_awk_makerealval (awk, r);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: error handling
|
||||
xp_awk_refdownval (awk, left);
|
||||
return XP_NULL;
|
||||
}
|
||||
}
|
||||
else if (nde->opcode == XP_AWK_UNROP_MINUS)
|
||||
{
|
||||
if (left->type == XP_AWK_VAL_INT)
|
||||
{
|
||||
xp_long_t r = ((xp_awk_val_int_t*)left)->val;
|
||||
res = xp_awk_makeintval (awk, -r);
|
||||
}
|
||||
else if (left->type == XP_AWK_VAL_REAL)
|
||||
{
|
||||
xp_real_t r = ((xp_awk_val_real_t*)left)->val;
|
||||
res = xp_awk_makerealval (awk, -r);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: error handling
|
||||
xp_awk_refdownval (awk, left);
|
||||
return XP_NULL;
|
||||
}
|
||||
}
|
||||
else if (nde->opcode == XP_AWK_UNROP_NOT)
|
||||
{
|
||||
if (left->type == XP_AWK_VAL_INT)
|
||||
{
|
||||
xp_long_t r = ((xp_awk_val_int_t*)left)->val;
|
||||
res = xp_awk_makeintval (awk, !r);
|
||||
}
|
||||
else if (left->type == XP_AWK_VAL_REAL)
|
||||
{
|
||||
xp_real_t r = ((xp_awk_val_real_t*)left)->val;
|
||||
res = xp_awk_makerealval (awk, !r);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: error handling
|
||||
xp_awk_refdownval (awk, left);
|
||||
return XP_NULL;
|
||||
}
|
||||
}
|
||||
else if (nde->opcode == XP_AWK_UNROP_BNOT)
|
||||
{
|
||||
if (left->type == XP_AWK_VAL_INT)
|
||||
{
|
||||
xp_long_t r = ((xp_awk_val_int_t*)left)->val;
|
||||
res = xp_awk_makeintval (awk, ~r);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: error handling
|
||||
xp_awk_refdownval (awk, left);
|
||||
return XP_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xp_awk_refdownval (awk, left);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static xp_awk_val_t* __eval_incpre (xp_awk_t* awk, xp_awk_nde_exp_t* nde)
|
||||
{
|
||||
xp_awk_val_t* left, * res;
|
||||
|
||||
xp_assert (nde->type == XP_AWK_NDE_EXP_INCPRE);
|
||||
xp_assert (nde->right == XP_NULL);
|
||||
|
||||
left = __eval_expression (awk, nde->left); // TODO: do it differently
|
||||
if (left == XP_NULL) return XP_NULL;
|
||||
|
||||
xp_awk_refupval (left);
|
||||
|
||||
if (nde->opcode == XP_AWK_UNROP_PLUS)
|
||||
{
|
||||
if (left->type == XP_AWK_VAL_INT)
|
||||
{
|
||||
xp_long_t r = ((xp_awk_val_int_t*)left)->val;
|
||||
res = xp_awk_makeintval (awk, r + 1);
|
||||
}
|
||||
else if (left->type == XP_AWK_VAL_REAL)
|
||||
{
|
||||
xp_real_t r = ((xp_awk_val_real_t*)left)->val;
|
||||
res = xp_awk_makerealval (awk, r + 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
xp_awk_refdownval (awk, left);
|
||||
return XP_NULL;
|
||||
}
|
||||
}
|
||||
else if (nde->opcode == XP_AWK_UNROP_MINUS)
|
||||
{
|
||||
if (left->type == XP_AWK_VAL_INT)
|
||||
{
|
||||
xp_long_t r = ((xp_awk_val_int_t*)left)->val;
|
||||
res = xp_awk_makeintval (awk, r - 1);
|
||||
}
|
||||
else if (left->type == XP_AWK_VAL_REAL)
|
||||
{
|
||||
xp_real_t r = ((xp_awk_val_real_t*)left)->val;
|
||||
res = xp_awk_makerealval (awk, r - 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
xp_awk_refdownval (awk, left);
|
||||
return XP_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xp_awk_refdownval (awk, left);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static xp_awk_val_t* __eval_incpst (xp_awk_t* awk, xp_awk_nde_exp_t* nde)
|
||||
{
|
||||
xp_awk_val_t* left, * res;
|
||||
|
||||
xp_assert (nde->type == XP_AWK_NDE_EXP_INCPST);
|
||||
xp_assert (nde->right == XP_NULL);
|
||||
|
||||
left = __eval_expression (awk, nde->left); // TODO: get the actual target...
|
||||
if (left == XP_NULL) return XP_NULL;
|
||||
|
||||
xp_awk_refupval (left);
|
||||
|
||||
if (nde->opcode == XP_AWK_UNROP_PLUS)
|
||||
{
|
||||
if (left->type == XP_AWK_VAL_INT)
|
||||
{
|
||||
xp_long_t r = ((xp_awk_val_int_t*)left)->val;
|
||||
res = xp_awk_makeintval (awk, r);
|
||||
|
||||
// TODO: increment the actual target...
|
||||
}
|
||||
else if (left->type == XP_AWK_VAL_REAL)
|
||||
{
|
||||
xp_real_t r = ((xp_awk_val_real_t*)left)->val;
|
||||
res = xp_awk_makerealval (awk, r);
|
||||
|
||||
// TODO: increment the actual target...
|
||||
}
|
||||
else
|
||||
{
|
||||
xp_awk_refdownval (awk, left);
|
||||
return XP_NULL;
|
||||
}
|
||||
}
|
||||
else if (nde->opcode == XP_AWK_UNROP_MINUS)
|
||||
{
|
||||
if (left->type == XP_AWK_VAL_INT)
|
||||
{
|
||||
xp_long_t r = ((xp_awk_val_int_t*)left)->val;
|
||||
res = xp_awk_makeintval (awk, r - 1);
|
||||
}
|
||||
else if (left->type == XP_AWK_VAL_REAL)
|
||||
{
|
||||
xp_real_t r = ((xp_awk_val_real_t*)left)->val;
|
||||
res = xp_awk_makerealval (awk, r - 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
xp_awk_refdownval (awk, left);
|
||||
return XP_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xp_awk_refdownval (awk, left);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static xp_awk_val_t* __eval_funccall (xp_awk_t* awk, xp_awk_nde_call_t* nde)
|
||||
{
|
||||
xp_awk_func_t* func;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.h,v 1.5 2006-03-31 12:04:14 bacon Exp $
|
||||
* $Id: run.h,v 1.6 2006-04-02 12:41:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_AWK_RUN_H_
|
||||
@ -22,8 +22,7 @@ struct xp_awk_frm_t
|
||||
enum
|
||||
{
|
||||
/* if you change this, you have to change
|
||||
* __binop_str in tree.c accordingly */
|
||||
|
||||
* __binop_str in tree.c accordingly. */
|
||||
XP_AWK_BINOP_LOR,
|
||||
XP_AWK_BINOP_LAND,
|
||||
XP_AWK_BINOP_BOR,
|
||||
@ -49,12 +48,20 @@ enum
|
||||
|
||||
enum
|
||||
{
|
||||
XP_AWK_UNAOP_PLUS,
|
||||
XP_AWK_UNAOP_MINUS,
|
||||
XP_AWK_UNAOP_PLUSPLUS,
|
||||
XP_AWK_UNAOP_MINUSMINUS,
|
||||
XP_AWK_UNAOP_NOT,
|
||||
XP_AWK_UNAOP_BNOT
|
||||
/* if you change this, you have to change
|
||||
* __unrop_str in tree.c accordingly. */
|
||||
XP_AWK_UNROP_PLUS,
|
||||
XP_AWK_UNROP_MINUS,
|
||||
XP_AWK_UNROP_NOT,
|
||||
XP_AWK_UNROP_BNOT
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/* if you change this, you have to change
|
||||
* __incop_str in tree.c accordingly. */
|
||||
XP_AWK_INCOP_PLUS,
|
||||
XP_AWK_INCOP_MINUS
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: tree.c,v 1.30 2006-03-31 16:35:37 bacon Exp $
|
||||
* $Id: tree.c,v 1.31 2006-04-02 12:41:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk_i.h>
|
||||
@ -35,16 +35,22 @@ static const xp_char_t* __binop_str[] =
|
||||
XP_TEXT("%")
|
||||
};
|
||||
|
||||
static const xp_char_t* __unaop_str[] =
|
||||
static const xp_char_t* __unrop_str[] =
|
||||
{
|
||||
XP_TEXT("+"),
|
||||
XP_TEXT("-"),
|
||||
XP_TEXT("++"),
|
||||
XP_TEXT("--"),
|
||||
XP_TEXT("!"),
|
||||
XP_TEXT("~")
|
||||
};
|
||||
|
||||
static const xp_char_t* __incop_str[] =
|
||||
{
|
||||
XP_TEXT("++"),
|
||||
XP_TEXT("--"),
|
||||
XP_TEXT("++"),
|
||||
XP_TEXT("--")
|
||||
};
|
||||
|
||||
static void __print_tabs (int depth);
|
||||
static int __print_expression (xp_awk_nde_t* nde);
|
||||
static int __print_expression_list (xp_awk_nde_t* tree);
|
||||
@ -68,19 +74,49 @@ static int __print_expression (xp_awk_nde_t* nde)
|
||||
|
||||
case XP_AWK_NDE_EXP_BIN:
|
||||
xp_printf (XP_TEXT("("));
|
||||
if (__print_expression (((xp_awk_nde_exp_t*)nde)->left) == -1) return -1;
|
||||
if (__print_expression(((xp_awk_nde_exp_t*)nde)->left) == -1)
|
||||
return -1;
|
||||
xp_assert ((((xp_awk_nde_exp_t*)nde)->left)->next == XP_NULL);
|
||||
xp_printf (XP_TEXT(" %s "), __binop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
||||
if (((xp_awk_nde_exp_t*)nde)->right->type == XP_AWK_NDE_ASS) xp_printf (XP_TEXT("("));
|
||||
if (__print_expression (((xp_awk_nde_exp_t*)nde)->right) == -1) return -1;
|
||||
if (((xp_awk_nde_exp_t*)nde)->right->type == XP_AWK_NDE_ASS) xp_printf (XP_TEXT(")"));
|
||||
xp_printf (XP_TEXT(" %s "),
|
||||
__binop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
||||
if (((xp_awk_nde_exp_t*)nde)->right->type == XP_AWK_NDE_ASS)
|
||||
xp_printf (XP_TEXT("("));
|
||||
if (__print_expression (((xp_awk_nde_exp_t*)nde)->right) == -1)
|
||||
return -1;
|
||||
if (((xp_awk_nde_exp_t*)nde)->right->type == XP_AWK_NDE_ASS)
|
||||
xp_printf (XP_TEXT(")"));
|
||||
xp_assert ((((xp_awk_nde_exp_t*)nde)->right)->next == XP_NULL);
|
||||
xp_printf (XP_TEXT(")"));
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_EXP_UNR:
|
||||
// TODO:
|
||||
xp_printf (XP_TEXT("unary basic expression\n"));
|
||||
xp_assert (((xp_awk_nde_exp_t*)nde)->right == XP_NULL);
|
||||
|
||||
xp_printf (XP_TEXT("%s("),
|
||||
__unrop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
||||
if (__print_expression (((xp_awk_nde_exp_t*)nde)->left) == -1)
|
||||
return -1;
|
||||
xp_printf (XP_TEXT(")"));
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_EXP_INCPRE:
|
||||
xp_assert (((xp_awk_nde_exp_t*)nde)->right == XP_NULL);
|
||||
|
||||
xp_printf (XP_TEXT("%s("),
|
||||
__incop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
||||
if (__print_expression (((xp_awk_nde_exp_t*)nde)->left) == -1)
|
||||
return -1;
|
||||
xp_printf (XP_TEXT(")"));
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_EXP_INCPST:
|
||||
xp_assert (((xp_awk_nde_exp_t*)nde)->right == XP_NULL);
|
||||
|
||||
xp_printf (XP_TEXT("("));
|
||||
if (__print_expression (((xp_awk_nde_exp_t*)nde)->left) == -1)
|
||||
return -1;
|
||||
xp_printf (XP_TEXT(")%s"),
|
||||
__incop_str[((xp_awk_nde_exp_t*)nde)->opcode]);
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_INT:
|
||||
@ -504,7 +540,10 @@ void xp_awk_clrpt (xp_awk_nde_t* tree)
|
||||
break;
|
||||
|
||||
case XP_AWK_NDE_EXP_UNR:
|
||||
// TODO: clear unary expression...
|
||||
case XP_AWK_NDE_EXP_INCPRE:
|
||||
case XP_AWK_NDE_EXP_INCPST:
|
||||
xp_assert (((xp_awk_nde_exp_t*)p)->right == XP_NULL);
|
||||
xp_awk_clrpt (((xp_awk_nde_exp_t*)p)->left);
|
||||
xp_free (p);
|
||||
break;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: tree.h,v 1.28 2006-03-28 16:33:09 bacon Exp $
|
||||
* $Id: tree.h,v 1.29 2006-04-02 12:41:14 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_AWK_TREE_H_
|
||||
@ -18,6 +18,8 @@ enum
|
||||
|
||||
XP_AWK_NDE_EXP_BIN,
|
||||
XP_AWK_NDE_EXP_UNR,
|
||||
XP_AWK_NDE_EXP_INCPRE,
|
||||
XP_AWK_NDE_EXP_INCPST,
|
||||
|
||||
XP_AWK_NDE_INT,
|
||||
XP_AWK_NDE_REAL,
|
||||
@ -101,13 +103,14 @@ struct xp_awk_nde_ass_t
|
||||
xp_awk_nde_t* right;
|
||||
};
|
||||
|
||||
/* XP_AWK_NDE_EXP_BIN, XP_AWK_NDE_EXP_UNR */
|
||||
/* XP_AWK_NDE_EXP_BIN, XP_AWK_NDE_EXP_UNR,
|
||||
* XP_AWK_NDE_EXP_INCPRE, XP_AWNDE_EXP_INCPST */
|
||||
struct xp_awk_nde_exp_t
|
||||
{
|
||||
XP_AWK_NDE_HDR;
|
||||
int opcode;
|
||||
xp_awk_nde_t* left;
|
||||
xp_awk_nde_t* right; /* optional for XP_AWK_NDE_UNR */
|
||||
xp_awk_nde_t* right; /* XP_NULL for UNR, INCPRE, INCPST */
|
||||
};
|
||||
|
||||
/* XP_AWK_NDE_POS - positional - $1, $2, $x, etc */
|
||||
|
@ -1,7 +1,7 @@
|
||||
CC = cl
|
||||
#CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\..
|
||||
CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\..
|
||||
LDFLAGS = /libpath:..\..\bas /libpath:..\..\awk\debug
|
||||
LDFLAGS = /libpath:..\..\bas /libpath:..\..\awk
|
||||
LIBS = xpbas.lib xpawk.lib
|
||||
#LIBS = xpawk.lib
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user