*** empty log message ***

This commit is contained in:
hyung-hwan 2006-02-05 13:45:59 +00:00
parent b54441bfc1
commit 2280d6563c
6 changed files with 77 additions and 41 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.17 2006-02-04 19:31:51 bacon Exp $
* $Id: awk.c,v 1.18 2006-02-05 13:45:59 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -131,6 +131,7 @@ 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")
};
if (awk->errnum >= 0 && awk->errnum < xp_countof(__errstr)) {

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h,v 1.24 2006-02-04 19:31:51 bacon Exp $
* $Id: awk.h,v 1.25 2006-02-05 13:45:59 bacon Exp $
*/
#ifndef _XP_AWK_AWK_H_
@ -46,7 +46,8 @@ enum
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_EDUPNAME, /* duplicate name - function, variable, etc */
XP_AWK_EUNDEF /* undefined identifier */
};
/*
@ -71,9 +72,10 @@ enum
/* parse options */
enum
{
XP_AWK_EXPLICIT = (1 << 0), /* variable requires explicit declaration */
XP_AWK_UNIQUE = (1 << 1), /* a function name should not coincide to be a variable name */
XP_AWK_SHADING = (1 << 2) /* allow variable shading */
XP_AWK_IMPLICIT = (1 << 0), /* allow undeclared variables */
XP_AWK_EXPLICIT = (1 << 1), /* variable requires explicit declaration */
XP_AWK_UNIQUE = (1 << 2), /* a function name should not coincide to be a variable name */
XP_AWK_SHADING = (1 << 3) /* allow variable shading */
};
struct xp_awk_t

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.45 2006-02-05 06:10:43 bacon Exp $
* $Id: parse.c,v 1.46 2006-02-05 13:45:59 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -191,9 +191,16 @@ static struct __kwent __kwtab[] =
static int __dump_func (xp_awk_pair_t* pair)
{
xp_awk_func_t* func = (xp_awk_func_t*)pair->value;
xp_size_t i;
xp_assert (xp_strcmp(pair->key, func->name) == 0);
xp_printf (XP_TEXT("function %s (nargs=>%u)\n"), func->name, func->nargs);
xp_printf (XP_TEXT("function %s ("), func->name);
for (i = 0; i < func->nargs; ) {
xp_printf (XP_TEXT("__arg%lu"), (unsigned long)i++);
if (i >= func->nargs) break;
xp_printf (XP_TEXT(", "));
}
xp_printf (XP_TEXT(")\n"));
xp_awk_prnpt (func->body);
xp_printf (XP_TEXT("\n"));
@ -1012,34 +1019,33 @@ static xp_awk_node_t* __parse_primary (xp_awk_t* awk)
return (xp_awk_node_t*)node;
}
/* search the variable name list */
// TODO:
idxa = __find_variable (awk, name_dup);
if (idxa == (xp_size_t)-1) {
idxa = __find_func_arg (awk, name_dup);
if (idxa == (xp_size_t)-1) {
node->type = XP_AWK_NODE_VAR;
node->next = XP_NULL;
node->id.name = name_dup;
}
else {
node->type = XP_AWK_NODE_ARG;
node->next = XP_NULL;
// TODO: do i need to store the name here???
node->id.name = name_dup;
node->id.idxa = idxa;
}
}
else {
// TODO: differentiate VAR with NAMED_VAR...
/* search the local variable list */
idxa = xp_awk_tab_rfind(&awk->parse.locals, name_dup, 0);
if (idxa != (xp_size_t)-1) {
node->type = XP_AWK_NODE_VAR;
node->next = XP_NULL;
// TODO: do i need to store the name here???
//node->id.name = XP_NULL;
node->id.name = name_dup;
node->id.idxa = idxa;
return (xp_awk_node_t*)node;
}
return (xp_awk_node_t*)node;
/* TODO: search the global variable list... */
/* search the global variable list */
if (awk->opt.parse & XP_AWK_IMPLICIT) {
node->type = XP_AWK_NODE_VAR;
node->next = XP_NULL;
node->id.name = name_dup;
node->id.idxa = (xp_size_t)-1;
return (xp_awk_node_t*)node;
}
/* undefined variable */
xp_free (name_dup);
xp_free (node);
PANIC (awk, XP_AWK_EUNDEF);
}
}
else if (MATCH(awk,TOKEN_INTEGER)) {

View File

@ -1,5 +1,5 @@
/*
* $Id: tab.c,v 1.2 2006-01-30 14:45:12 bacon Exp $
* $Id: tab.c,v 1.3 2006-02-05 13:45:59 bacon Exp $
*/
#include <xp/awk/tab.h>
@ -161,3 +161,14 @@ xp_size_t xp_awk_tab_find (
return (xp_size_t)-1;
}
xp_size_t xp_awk_tab_rfind (
xp_awk_tab_t* tab, const xp_char_t* value, xp_size_t index)
{
xp_size_t i;
for (i = index + 1; i-- > 0; ) {
if (xp_strcmp(tab->buf[i], value) == 0) return i;
}
return (xp_size_t)-1;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: tab.h,v 1.1 2006-01-29 18:28:14 bacon Exp $
* $Id: tab.h,v 1.2 2006-02-05 13:45:59 bacon Exp $
*/
#ifndef _XP_AWK_TAB_H_
@ -46,6 +46,8 @@ xp_size_t xp_awk_tab_remrange (
xp_size_t xp_awk_tab_adddatum (xp_awk_tab_t* tab, const xp_char_t* value);
xp_size_t xp_awk_tab_find (
xp_awk_tab_t* tab, const xp_char_t* value, xp_size_t index);
xp_size_t xp_awk_tab_rfind (
xp_awk_tab_t* tab, const xp_char_t* value, xp_size_t index);
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.c,v 1.17 2006-02-05 06:10:43 bacon Exp $
* $Id: tree.c,v 1.18 2006-02-05 13:45:59 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -66,23 +66,37 @@ static int __print_expr_node (xp_awk_node_t* node)
break;
case XP_AWK_NODE_ARG:
xp_printf (XP_TEXT("__arg%u"),
(unsigned int)((xp_awk_node_var_t*)node)->id.idxa);
xp_assert (((xp_awk_node_var_t*)node)->id.idxa != (xp_size_t)-1);
xp_printf (XP_TEXT("__arg%lu"),
(unsigned long)((xp_awk_node_var_t*)node)->id.idxa);
break;
case XP_AWK_NODE_ARGIDX:
xp_printf (XP_TEXT("__arg%u["),
(unsigned int)((xp_awk_node_idx_t*)node)->id.idxa);
xp_assert (((xp_awk_node_var_t*)node)->id.idxa != (xp_size_t)-1);
xp_printf (XP_TEXT("__arg%lu["),
(unsigned long)((xp_awk_node_idx_t*)node)->id.idxa);
__print_expr_node (((xp_awk_node_idx_t*)node)->idx);
xp_printf (XP_TEXT("]"));
break;
case XP_AWK_NODE_VAR:
xp_printf (XP_TEXT("%s"), ((xp_awk_node_var_t*)node)->id.name);
if (((xp_awk_node_var_t*)node)->id.idxa != (xp_size_t)-1) {
xp_printf (XP_TEXT("__local%lu"),
(unsigned long)((xp_awk_node_var_t*)node)->id.idxa);
}
else {
xp_printf (XP_TEXT("%s"), ((xp_awk_node_var_t*)node)->id.name);
}
break;
case XP_AWK_NODE_VARIDX:
xp_printf (XP_TEXT("%s["), ((xp_awk_node_idx_t*)node)->id.name);
if (((xp_awk_node_idx_t*)node)->id.idxa != (xp_size_t)-1) {
xp_printf (XP_TEXT("__local%lu["),
(unsigned long)((xp_awk_node_idx_t*)node)->id.idxa);
}
else {
xp_printf (XP_TEXT("%s["), ((xp_awk_node_idx_t*)node)->id.name);
}
__print_expr_node (((xp_awk_node_idx_t*)node)->idx);
xp_printf (XP_TEXT("]"));
break;
@ -140,9 +154,9 @@ static void __print_statements (xp_awk_node_t* tree, int depth)
xp_printf (XP_TEXT("local "));
for (i = 0; i < ((xp_awk_node_block_t*)p)->nlocals - 1; i++) {
xp_printf (XP_TEXT("__local%u, "), (unsigned int)i);
xp_printf (XP_TEXT("__local%lu, "), (unsigned long)i);
}
xp_printf (XP_TEXT("__local%u;\n"), (unsigned int)i);
xp_printf (XP_TEXT("__local%lu;\n"), (unsigned long)i);
}
__print_statements (((xp_awk_node_block_t*)p)->body, depth + 1);