*** empty log message ***
This commit is contained in:
parent
8c1381e106
commit
40b9f15b5c
@ -1,4 +1,4 @@
|
||||
/* * $Id: awk.c,v 1.22 2006-02-23 14:42:33 bacon Exp $ */
|
||||
/* * $Id: awk.c,v 1.23 2006-02-23 15:37:34 bacon Exp $ */
|
||||
|
||||
#include <xp/awk/awk.h>
|
||||
|
||||
@ -53,6 +53,17 @@ xp_awk_t* xp_awk_open (xp_awk_t* awk)
|
||||
return XP_NULL;
|
||||
}
|
||||
|
||||
/* TODO: maybe a free function .... */
|
||||
if (xp_awk_hash_open(&awk->run.named, 256, XP_NULL) == XP_NULL) {
|
||||
xp_str_close (&awk->token.name);
|
||||
xp_awk_hash_close (&awk->tree.funcs);
|
||||
xp_awk_tab_close (&awk->parse.globals);
|
||||
xp_awk_tab_close (&awk->parse.locals);
|
||||
xp_awk_tab_close (&awk->parse.params);
|
||||
if (awk->__dynamic) xp_free (awk);
|
||||
return XP_NULL;
|
||||
}
|
||||
|
||||
awk->opt.parse = 0;
|
||||
awk->opt.run = 0;
|
||||
awk->errnum = XP_AWK_ENOERR;
|
||||
@ -82,6 +93,7 @@ int xp_awk_close (xp_awk_t* awk)
|
||||
xp_awk_tab_close (&awk->parse.globals);
|
||||
xp_awk_tab_close (&awk->parse.locals);
|
||||
xp_awk_tab_close (&awk->parse.params);
|
||||
xp_awk_hash_close (&awk->run.named);
|
||||
xp_str_close (&awk->token.name);
|
||||
if (awk->__dynamic) xp_free (awk);
|
||||
return 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h,v 1.28 2006-02-08 16:14:31 bacon Exp $
|
||||
* $Id: awk.h,v 1.29 2006-02-23 15:37:34 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_AWK_AWK_H_
|
||||
@ -118,6 +118,12 @@ struct xp_awk_t
|
||||
xp_size_t nlocals_max;
|
||||
} parse;
|
||||
|
||||
/* run-time data structure */
|
||||
struct
|
||||
{
|
||||
xp_awk_hash_t named;
|
||||
} run;
|
||||
|
||||
/* source buffer management */
|
||||
struct
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c,v 1.1 2006-01-26 15:35:20 bacon Exp $
|
||||
* $Id: run.c,v 1.2 2006-02-23 15:37:34 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/awk/awk.h>
|
||||
@ -9,6 +9,8 @@
|
||||
|
||||
static int __run_block (xp_awk_t* awk, xp_awk_node_t* node);
|
||||
static int __run_statement (xp_awk_t* awk, xp_awk_node_t* node);
|
||||
static int __run_assignment (xp_awk_t* awk, xp_awk_node_assign_t* node);
|
||||
static int __eval_expr (xp_awk_t* awk, xp_awk_node_t* node);
|
||||
|
||||
int xp_awk_run (xp_awk_t* awk)
|
||||
{
|
||||
@ -26,20 +28,102 @@ int xp_awk_run (xp_awk_t* awk)
|
||||
static int __run_block (xp_awk_t* awk, xp_awk_node_t* node)
|
||||
{
|
||||
xp_assert (node->type == XP_AWK_NODE_BLOCK);
|
||||
return -1;
|
||||
|
||||
xp_awk_node_t* p = node;
|
||||
|
||||
while (p != XP_NULL) {
|
||||
|
||||
if (__run_statement (awk, p) == -1) return -1;
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __run_statement (xp_awk_t* awk, xp_awk_node_t* node)
|
||||
{
|
||||
switch (node->type) {
|
||||
case XP_AWK_NODE_NULL:
|
||||
/* do nothing */
|
||||
break;
|
||||
|
||||
case XP_AWK_NODE_BLOCK:
|
||||
if (__run_block(awk, node) == -1) return -1;
|
||||
break;
|
||||
|
||||
case XP_AWK_NODE_IF:
|
||||
break;
|
||||
case XP_AWK_NODE_WHILE:
|
||||
break;
|
||||
case XP_AWK_NODE_DOWHILE:
|
||||
break;
|
||||
case XP_AWK_NODE_FOR:
|
||||
break;
|
||||
|
||||
case XP_AWK_NODE_BREAK:
|
||||
break;
|
||||
case XP_AWK_NODE_CONTINUE:
|
||||
break;
|
||||
|
||||
case XP_AWK_NODE_RETURN:
|
||||
break;
|
||||
|
||||
case XP_AWK_NODE_EXIT:
|
||||
break;
|
||||
|
||||
case XP_AWK_NODE_NEXT:
|
||||
break;
|
||||
|
||||
case XP_AWK_NODE_NEXTFILE:
|
||||
break;
|
||||
|
||||
case XP_AWK_NODE_ASSIGN:
|
||||
if (__run_assignment (awk, node) == -1) return -1;
|
||||
break;
|
||||
|
||||
case XP_AWK_NODE_NUM:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __run_assignment (xp_awk_t* awk, xp_awk_node_assign_t* node)
|
||||
{
|
||||
if (node->type == XP_AWK_NODE_NAMED) {
|
||||
xp_awk_node_t* right = __eval_expr (awk, node->right);
|
||||
if (right == NULL) return -1;
|
||||
|
||||
if (xp_awk_hash_insert(awk->run.named, right) == -1) {
|
||||
awk->errnum = XP_AWK_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (node->type == XP_AWK_NODE_GLOBAL) {
|
||||
}
|
||||
else if (node->type == XP_AWK_NODE_LOCAL) {
|
||||
}
|
||||
else if (node->type == XP_AWK_NODE_ARG) {
|
||||
}
|
||||
|
||||
else if (node->type == XP_AWK_NODE_NAMEIDX) {
|
||||
}
|
||||
else if (node->type == XP_AWK_NODE_GLOBALIDX) {
|
||||
}
|
||||
else if (node->type == XP_AWK_NODE_LOCALIDX) {
|
||||
}
|
||||
else if (node->type == XP_AWK_NODE_ARGIDX) {
|
||||
}
|
||||
|
||||
esle {
|
||||
awk->errnum = XP_AWK_EINTERNAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __eval_expr (xp_awk_t* awk, xp_awk_node_t* node)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user