Recovered from cvs revision 2007-06-18 14:05:00

This commit is contained in:
hyung-hwan 2007-06-18 23:26:00 +00:00
parent 8635f49f5b
commit fdb13f1536
7 changed files with 98 additions and 277 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.5 2007/05/06 10:38:22 bacon Exp $ * $Id: awk.c,v 1.7 2007/06/17 14:54:10 bacon Exp $
* *
* {License} * {License}
*/ */
@ -11,6 +11,7 @@
#include <ase/awk/awk_i.h> #include <ase/awk/awk_i.h>
static void free_kw (void* awk, void* ptr);
static void free_afn (void* awk, void* afn); static void free_afn (void* awk, void* afn);
ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data) ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
@ -57,10 +58,19 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
return ASE_NULL; return ASE_NULL;
} }
awk->kwtab = ase_awk_map_open (awk, 512, free_kw, awk);
if (awk->kwtab == ASE_NULL)
{
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
/* TODO: initial map size?? */ /* TODO: initial map size?? */
awk->tree.afns = ase_awk_map_open (awk, 256, free_afn, awk); awk->tree.afns = ase_awk_map_open (awk, 512, free_afn, awk);
if (awk->tree.afns == ASE_NULL) if (awk->tree.afns == ASE_NULL)
{ {
ase_awk_map_close (awk->kwtab);
ase_str_close (&awk->token.name); ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
@ -68,27 +78,30 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL) if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL)
{ {
ase_str_close (&awk->token.name);
ase_awk_map_close (awk->tree.afns); ase_awk_map_close (awk->tree.afns);
ase_awk_map_close (awk->kwtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
if (ase_awk_tab_open (&awk->parse.locals, awk) == ASE_NULL) if (ase_awk_tab_open (&awk->parse.locals, awk) == ASE_NULL)
{ {
ase_str_close (&awk->token.name);
ase_awk_map_close (awk->tree.afns);
ase_awk_tab_close (&awk->parse.globals); ase_awk_tab_close (&awk->parse.globals);
ase_awk_map_close (awk->tree.afns);
ase_awk_map_close (awk->kwtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
if (ase_awk_tab_open (&awk->parse.params, awk) == ASE_NULL) if (ase_awk_tab_open (&awk->parse.params, awk) == ASE_NULL)
{ {
ase_str_close (&awk->token.name);
ase_awk_map_close (awk->tree.afns);
ase_awk_tab_close (&awk->parse.globals);
ase_awk_tab_close (&awk->parse.locals); ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_awk_map_close (awk->tree.afns);
ase_awk_map_close (awk->kwtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
@ -136,9 +149,15 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_REX_MATCH, 0); ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_REX_MATCH, 0);
awk->custom_data = custom_data; awk->custom_data = custom_data;
return awk; return awk;
} }
static void free_kw (void* owner, void* ptr)
{
ASE_AWK_FREE ((ase_awk_t*)owner, ptr);
}
static void free_afn (void* owner, void* afn) static void free_afn (void* owner, void* afn)
{ {
ase_awk_afn_t* f = (ase_awk_afn_t*)afn; ase_awk_afn_t* f = (ase_awk_afn_t*)afn;
@ -157,10 +176,11 @@ int ase_awk_close (ase_awk_t* awk)
if (ase_awk_clear (awk) == -1) return -1; if (ase_awk_clear (awk) == -1) return -1;
ase_awk_clrbfn (awk); ase_awk_clrbfn (awk);
ase_awk_map_close (awk->tree.afns);
ase_awk_tab_close (&awk->parse.globals);
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.params); ase_awk_tab_close (&awk->parse.params);
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_awk_map_close (awk->tree.afns);
ase_awk_map_close (awk->kwtab);
ase_str_close (&awk->token.name); ase_str_close (&awk->token.name);
for (i = 0; i < ASE_COUNTOF(awk->errstr); i++) for (i = 0; i < ASE_COUNTOF(awk->errstr); i++)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h,v 1.5 2007/05/19 12:13:41 bacon Exp $ * $Id: awk.h,v 1.6 2007/06/17 14:54:10 bacon Exp $
* *
* {License} * {License}
*/ */
@ -414,6 +414,10 @@ void ase_awk_setoption (ase_awk_t* awk, int opt);
ase_size_t ase_awk_getmaxdepth (ase_awk_t* awk, int type); ase_size_t ase_awk_getmaxdepth (ase_awk_t* awk, int type);
void ase_awk_setmaxdepth (ase_awk_t* awk, int types, ase_size_t depth); void ase_awk_setmaxdepth (ase_awk_t* awk, int types, ase_size_t depth);
int ase_awk_setkeyword (ase_awk_t* awk,
const ase_char_t* okw, ase_size_t olen,
const ase_char_t* nkw, ase_size_t nlen);
int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios); int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios);
/* /*

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk_i.h,v 1.5 2007/05/06 10:08:54 bacon Exp $ * $Id: awk_i.h,v 1.6 2007/06/17 09:29:46 bacon Exp $
* *
* {License} * {License}
*/ */
@ -74,6 +74,9 @@ struct ase_awk_t
/* options */ /* options */
int option; int option;
/* keyword table */
ase_awk_map_t* kwtab;
/* parse tree */ /* parse tree */
ase_awk_tree_t tree; ase_awk_tree_t tree;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.5 2007/05/13 14:43:58 bacon Exp $ * $Id: parse.c,v 1.7 2007/06/17 15:29:29 bacon Exp $
* *
* {License} * {License}
*/ */
@ -397,6 +397,32 @@ const ase_char_t* ase_awk_getglobalname (
return gtab[idx].name; return gtab[idx].name;
} }
int ase_awk_setkeyword (ase_awk_t* awk,
const ase_char_t* okw, ase_size_t olen,
const ase_char_t* nkw, ase_size_t nlen)
{
ase_cstr_t* v;
ase_awk_pair_t* pair;
v = (ase_cstr_t*) ASE_AWK_MALLOC (
awk, ASE_SIZEOF(ase_cstr_t)+((nlen+1)*ASE_SIZEOF(*nkw)));
if (v == ASE_NULL) return -1;
v->len = nlen;
v->ptr = (const ase_char_t*)(v + 1);
ase_strxncpy (v->ptr, v->len+1, nkw, nlen);
if (ase_awk_map_put (awk->kwtab, okw, olen, v) == ASE_NULL)
{
ASE_AWK_FREE (awk, v);
return -1;
}
return 0;
}
int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios) int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios)
{ {
int n; int n;
@ -4744,14 +4770,32 @@ static int classify_ident (
ase_awk_t* awk, const ase_char_t* name, ase_size_t len) ase_awk_t* awk, const ase_char_t* name, ase_size_t len)
{ {
kwent_t* kwp; kwent_t* kwp;
ase_awk_pair_t* pair;
for (kwp = kwtab; kwp->name != ASE_NULL; kwp++) for (kwp = kwtab; kwp->name != ASE_NULL; kwp++)
{ {
const ase_char_t* k;
ase_size_t l;
if (kwp->valid != 0 && if (kwp->valid != 0 &&
(awk->option & kwp->valid) == 0) continue; (awk->option & kwp->valid) == 0) continue;
if (ase_strxncmp (kwp->name, kwp->name_len, name, len) == 0) pair = ase_awk_map_get (awk->kwtab, kwp->name, kwp->name_len);
if (pair != ASE_NULL)
{ {
k = ((ase_cstr_t*)(pair->val))->ptr;
l = ((ase_cstr_t*)(pair->val))->len;
}
else
{
k = kwp->name;
l = kwp->name_len;
}
if (ase_strxncmp (k, l, name, len) == 0)
{
return kwp->type; return kwp->type;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.9 2007/05/24 04:04:44 bacon Exp $ * $Id: awk.c,v 1.11 2007/06/17 15:29:29 bacon Exp $
*/ */
#include <ase/awk/awk.h> #include <ase/awk/awk.h>
@ -1080,6 +1080,8 @@ static int awk_main (int argc, ase_char_t* argv[])
ase_awk_setmaxdepth ( ase_awk_setmaxdepth (
awk, ASE_AWK_DEPTH_BLOCK_RUN | ASE_AWK_DEPTH_EXPR_RUN, 50); awk, ASE_AWK_DEPTH_BLOCK_RUN | ASE_AWK_DEPTH_EXPR_RUN, 50);
/*ase_awk_setkeyword (awk, ASE_T("func"), 4, ASE_T("FX"), 2);*/
if (ase_awk_parse (awk, &srcios) == -1) if (ase_awk_parse (awk, &srcios) == -1)
{ {
ase_printf ( ase_printf (

View File

@ -1,4 +1,4 @@
function sum(i, k, y) func sum(i, k, y)
{ {
y = 0; y = 0;
for (k = i; k; k = k - 1) for (k = i; k; k = k - 1)