*** empty log message ***

This commit is contained in:
hyung-hwan 2006-03-03 11:45:45 +00:00
parent 3b906ea35e
commit 3c9384a631
7 changed files with 799 additions and 721 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h,v 1.30 2006-03-02 15:10:59 bacon Exp $ * $Id: awk.h,v 1.31 2006-03-03 11:45:45 bacon Exp $
*/ */
#ifndef _XP_AWK_AWK_H_ #ifndef _XP_AWK_AWK_H_
@ -16,6 +16,7 @@
#include <xp/awk/tree.h> #include <xp/awk/tree.h>
#include <xp/awk/tab.h> #include <xp/awk/tab.h>
#include <xp/awk/map.h> #include <xp/awk/map.h>
#include <xp/awk/val.h>
enum enum
{ {
@ -39,7 +40,7 @@ enum
XP_AWK_EEXPR, /* expression expected */ XP_AWK_EEXPR, /* expression expected */
XP_AWK_EWHILE, /* keyword 'while' is expected */ XP_AWK_EWHILE, /* keyword 'while' is expected */
XP_AWK_EASSIGN, /* assignment statement expected */ XP_AWK_EASSIGNMENT, /* assignment statement expected */
XP_AWK_EIDENT, /* identifier expected */ XP_AWK_EIDENT, /* identifier expected */
XP_AWK_EDUPBEGIN, /* duplicate BEGIN */ XP_AWK_EDUPBEGIN, /* duplicate BEGIN */
XP_AWK_EDUPEND, /* duplicate END */ XP_AWK_EDUPEND, /* duplicate END */
@ -103,8 +104,8 @@ struct xp_awk_t
{ {
xp_size_t nglobals; xp_size_t nglobals;
xp_awk_map_t funcs; xp_awk_map_t funcs;
xp_awk_node_t* begin; xp_awk_nde_t* begin;
xp_awk_node_t* end; xp_awk_nde_t* end;
xp_awk_chain_t* chain; xp_awk_chain_t* chain;
xp_awk_chain_t* chain_tail; xp_awk_chain_t* chain_tail;
} tree; } tree;
@ -146,8 +147,8 @@ struct xp_awk_t
struct xp_awk_chain_t struct xp_awk_chain_t
{ {
xp_awk_node_t* pattern; xp_awk_nde_t* pattern;
xp_awk_node_t* action; xp_awk_nde_t* action;
xp_awk_chain_t* next; xp_awk_chain_t* next;
}; };

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.4 2006-03-02 15:36:30 bacon Exp $ * $Id: run.c,v 1.5 2006-03-03 11:45:45 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk.h>
@ -8,127 +8,153 @@
#include <xp/bas/assert.h> #include <xp/bas/assert.h>
#endif #endif
static int __run_block (xp_awk_t* awk, xp_awk_node_t* node); static int __run_block (xp_awk_t* awk, xp_awk_nde_t* nde);
static int __run_statement (xp_awk_t* awk, xp_awk_node_t* node); static int __run_statement (xp_awk_t* awk, xp_awk_nde_t* nde);
static int __run_assignment (xp_awk_t* awk, xp_awk_node_assign_t* node); static int __run_assignment (xp_awk_t* awk, xp_awk_nde_ass_t* nde);
static int __eval_expr (xp_awk_t* awk, xp_awk_node_t* node);
static xp_awk_val_t* __eval_expr (xp_awk_t* awk, xp_awk_nde_t* nde);
int xp_awk_run (xp_awk_t* awk) int xp_awk_run (xp_awk_t* awk)
{ {
if (awk->tree.begin != XP_NULL) { if (awk->tree.begin != XP_NULL)
{
if (__run_block(awk, awk->tree.begin) == -1) return -1; if (__run_block(awk, awk->tree.begin) == -1) return -1;
} }
if (awk->tree.end != XP_NULL) { if (awk->tree.end != XP_NULL)
{
if (__run_block(awk, awk->tree.end) == -1) return -1; if (__run_block(awk, awk->tree.end) == -1) return -1;
} }
return 0; return 0;
} }
static int __run_block (xp_awk_t* awk, xp_awk_node_t* node) static int __run_block (xp_awk_t* awk, xp_awk_nde_t* nde)
{ {
xp_assert (node->type == XP_AWK_NODE_BLOCK); xp_awk_nde_t* p;
/* xp_assert (nde->type == XP_AWK_NDE_BLOCK);
xp_awk_node_t* p = node;
while (p != XP_NULL) { p = nde;
if (__run_statement (awk, p) == -1) return -1; while (p != XP_NULL)
{
if (__run_statement(awk, p) == -1) return -1;
p = p->next; p = p->next;
} }
*/
return 0; return 0;
} }
static int __run_statement (xp_awk_t* awk, xp_awk_node_t* node) static int __run_statement (xp_awk_t* awk, xp_awk_nde_t* nde)
{ {
#if 0 switch (nde->type)
switch (node->type) { {
case XP_AWK_NODE_NULL: case XP_AWK_NDE_NULL:
/* do nothing */ /* do nothing */
break; break;
case XP_AWK_NODE_BLOCK: case XP_AWK_NDE_BLOCK:
if (__run_block(awk, node) == -1) return -1; if (__run_block(awk, nde) == -1) return -1;
break; break;
case XP_AWK_NODE_IF: #if 0
case XP_AWK_NDE_IF:
break; break;
case XP_AWK_NODE_WHILE: case XP_AWK_NDE_WHILE:
break; break;
case XP_AWK_NODE_DOWHILE: case XP_AWK_NDE_DOWHILE:
break; break;
case XP_AWK_NODE_FOR: case XP_AWK_NDE_FOR:
break; break;
case XP_AWK_NODE_BREAK: case XP_AWK_NDE_BREAK:
break; break;
case XP_AWK_NODE_CONTINUE: case XP_AWK_NDE_CONTINUE:
break; break;
case XP_AWK_NODE_RETURN: case XP_AWK_NDE_RETURN:
break; break;
case XP_AWK_NODE_EXIT: case XP_AWK_NDE_EXIT:
break; break;
case XP_AWK_NODE_NEXT: case XP_AWK_NDE_NEXT:
break; break;
case XP_AWK_NODE_NEXTFILE: case XP_AWK_NDE_NEXTFILE:
break;
#endif
case XP_AWK_NDE_ASS:
if (__run_assignment (
awk, (xp_awk_nde_ass_t*)nde) == -1) return -1;
break; break;
case XP_AWK_NODE_ASSIGN: #if 0
if (__run_assignment (awk, node) == -1) return -1; case XP_AWK_NDE_NUM:
break; break;
#endif
case XP_AWK_NODE_NUM: default:
break; /* this should never be reached */
// TODO: set errnum ....
return -1;
} }
return 0; return 0;
} }
static int __run_assignment (xp_awk_t* awk, xp_awk_node_assign_t* node) static int __run_assignment (xp_awk_t* awk, xp_awk_nde_ass_t* nde)
{ {
if (node->type == XP_AWK_NODE_NAMED) { if (nde->type == XP_AWK_NDE_NAMED)
xp_awk_node_t* right = __eval_expr (awk, node->right); {
if (right == NULL) return -1; xp_awk_nde_var_t* left = (xp_awk_nde_var_t*)nde->left;
xp_awk_val_t* right = __eval_expr (awk, nde->right);
if (xp_awk_map_insert(awk->run.named, right) == -1) { xp_assert (left != XP_NULL);
if (right == XP_NULL) return -1;
if (xp_awk_map_put (
&awk->run.named, left->id.name, right) == XP_NULL)
{
awk->errnum = XP_AWK_ENOMEM; awk->errnum = XP_AWK_ENOMEM;
return -1; return -1;
} }
} }
else if (node->type == XP_AWK_NODE_GLOBAL) { else if (nde->type == XP_AWK_NDE_GLOBAL)
{
} }
else if (node->type == XP_AWK_NODE_LOCAL) { else if (nde->type == XP_AWK_NDE_LOCAL)
{
} }
else if (node->type == XP_AWK_NODE_ARG) { else if (nde->type == XP_AWK_NDE_ARG)
{
} }
else if (node->type == XP_AWK_NODE_NAMEIDX) { else if (nde->type == XP_AWK_NDE_NAMEDIDX)
{
} }
else if (node->type == XP_AWK_NODE_GLOBALIDX) { else if (nde->type == XP_AWK_NDE_GLOBALIDX)
{
} }
else if (node->type == XP_AWK_NODE_LOCALIDX) { else if (nde->type == XP_AWK_NDE_LOCALIDX)
{
} }
else if (node->type == XP_AWK_NODE_ARGIDX) { else if (nde->type == XP_AWK_NDE_ARGIDX)
{
} }
else
esle { {
awk->errnum = XP_AWK_EINTERNAL; /* this should never be reached */
// TODO: set errnum ....
return -1; return -1;
} }
#endif
return 0; return 0;
} }
static int __eval_expr (xp_awk_t* awk, xp_awk_node_t* node) static xp_awk_val_t* __eval_expr (xp_awk_t* awk, xp_awk_nde_t* nde)
{ {
return -1; return XP_NULL;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: sa.h,v 1.10 2006-02-18 16:14:14 bacon Exp $ * $Id: sa.h,v 1.11 2006-03-03 11:45:45 bacon Exp $
*/ */
#ifndef _XP_AWK_SA_H_ #ifndef _XP_AWK_SA_H_
@ -67,10 +67,13 @@ typedef ssize_t xp_ssize_t;
#if defined(_WIN32) #if defined(_WIN32)
typedef __int64 xp_long_t; typedef __int64 xp_long_t;
typedef long double xp_real_t;
#elif defined(vax) || defined(__vax) #elif defined(vax) || defined(__vax)
typedef long xp_long_t; typedef long xp_long_t;
typedef long double xp_real_t;
#else #else
typedef long long xp_long_t; typedef long long xp_long_t;
typedef long double xp_real_t;
#endif #endif
#define XP_STR_LEN(x) ((x)->size) #define XP_STR_LEN(x) ((x)->size)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.c,v 1.20 2006-02-08 16:14:31 bacon Exp $ * $Id: tree.c,v 1.21 2006-03-03 11:45:45 bacon Exp $
*/ */
#include <xp/awk/awk.h> #include <xp/awk/awk.h>
@ -28,9 +28,9 @@ static const xp_char_t* __binop_str[] =
}; };
static void __print_tabs (int depth); static void __print_tabs (int depth);
static int __print_expr_node (xp_awk_node_t* node); static int __print_expr_nde (xp_awk_nde_t* nde);
static int __print_expr_node_list (xp_awk_node_t* tree); static int __print_expr_nde_list (xp_awk_nde_t* tree);
static void __print_statements (xp_awk_node_t* tree, int depth); static void __print_statements (xp_awk_nde_t* tree, int depth);
static void __print_tabs (int depth) static void __print_tabs (int depth)
{ {
@ -38,119 +38,119 @@ static void __print_tabs (int depth)
for (i = 0; i < depth; i++) xp_printf (XP_TEXT("\t")); for (i = 0; i < depth; i++) xp_printf (XP_TEXT("\t"));
} }
static int __print_expr_node (xp_awk_node_t* node) static int __print_expr_nde (xp_awk_nde_t* nde)
{ {
switch (node->type) { switch (nde->type) {
case XP_AWK_NODE_ASSIGN: case XP_AWK_NDE_ASS:
if (__print_expr_node (((xp_awk_node_assign_t*)node)->left) == -1) return -1; if (__print_expr_nde (((xp_awk_nde_ass_t*)nde)->left) == -1) return -1;
xp_printf (XP_TEXT(" = ")); xp_printf (XP_TEXT(" = "));
if (__print_expr_node (((xp_awk_node_assign_t*)node)->right) == -1) return -1; if (__print_expr_nde (((xp_awk_nde_ass_t*)nde)->right) == -1) return -1;
xp_assert ((((xp_awk_node_assign_t*)node)->right)->next == XP_NULL); xp_assert ((((xp_awk_nde_ass_t*)nde)->right)->next == XP_NULL);
break; break;
case XP_AWK_NODE_BINARY: case XP_AWK_NDE_BINARY:
xp_printf (XP_TEXT("(")); xp_printf (XP_TEXT("("));
if (__print_expr_node (((xp_awk_node_expr_t*)node)->left) == -1) return -1; if (__print_expr_nde (((xp_awk_nde_expr_t*)nde)->left) == -1) return -1;
xp_assert ((((xp_awk_node_expr_t*)node)->left)->next == XP_NULL); xp_assert ((((xp_awk_nde_expr_t*)nde)->left)->next == XP_NULL);
xp_printf (XP_TEXT(" %s "), __binop_str[((xp_awk_node_expr_t*)node)->opcode]); xp_printf (XP_TEXT(" %s "), __binop_str[((xp_awk_nde_expr_t*)nde)->opcode]);
if (((xp_awk_node_expr_t*)node)->right->type == XP_AWK_NODE_ASSIGN) xp_printf (XP_TEXT("(")); if (((xp_awk_nde_expr_t*)nde)->right->type == XP_AWK_NDE_ASS) xp_printf (XP_TEXT("("));
if (__print_expr_node (((xp_awk_node_expr_t*)node)->right) == -1) return -1; if (__print_expr_nde (((xp_awk_nde_expr_t*)nde)->right) == -1) return -1;
if (((xp_awk_node_expr_t*)node)->right->type == XP_AWK_NODE_ASSIGN) xp_printf (XP_TEXT(")")); if (((xp_awk_nde_expr_t*)nde)->right->type == XP_AWK_NDE_ASS) xp_printf (XP_TEXT(")"));
xp_assert ((((xp_awk_node_expr_t*)node)->right)->next == XP_NULL); xp_assert ((((xp_awk_nde_expr_t*)nde)->right)->next == XP_NULL);
xp_printf (XP_TEXT(")")); xp_printf (XP_TEXT(")"));
break; break;
case XP_AWK_NODE_UNARY: case XP_AWK_NDE_UNARY:
// TODO: // TODO:
xp_printf (XP_TEXT("unary basic expression\n")); xp_printf (XP_TEXT("unary basic expression\n"));
break; break;
case XP_AWK_NODE_STR: case XP_AWK_NDE_STR:
xp_printf (XP_TEXT("\"%s\""), ((xp_awk_node_term_t*)node)->value); xp_printf (XP_TEXT("\"%s\""), ((xp_awk_nde_term_t*)nde)->value);
break; break;
case XP_AWK_NODE_NUM: case XP_AWK_NDE_NUM:
xp_printf (XP_TEXT("%s"), ((xp_awk_node_term_t*)node)->value); xp_printf (XP_TEXT("%s"), ((xp_awk_nde_term_t*)nde)->value);
break; break;
case XP_AWK_NODE_ARG: case XP_AWK_NDE_ARG:
xp_assert (((xp_awk_node_var_t*)node)->id.idxa != (xp_size_t)-1); xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1);
xp_printf (XP_TEXT("__arg%lu"), xp_printf (XP_TEXT("__arg%lu"),
(unsigned long)((xp_awk_node_var_t*)node)->id.idxa); (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa);
break; break;
case XP_AWK_NODE_ARGIDX: case XP_AWK_NDE_ARGIDX:
xp_assert (((xp_awk_node_var_t*)node)->id.idxa != (xp_size_t)-1); xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1);
xp_printf (XP_TEXT("__arg%lu["), xp_printf (XP_TEXT("__arg%lu["),
(unsigned long)((xp_awk_node_idx_t*)node)->id.idxa); (unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa);
__print_expr_node (((xp_awk_node_idx_t*)node)->idx); __print_expr_nde (((xp_awk_nde_idx_t*)nde)->idx);
xp_printf (XP_TEXT("]")); xp_printf (XP_TEXT("]"));
break; break;
case XP_AWK_NODE_NAMED: case XP_AWK_NDE_NAMED:
xp_assert (((xp_awk_node_var_t*)node)->id.idxa == (xp_size_t)-1); xp_assert (((xp_awk_nde_var_t*)nde)->id.idxa == (xp_size_t)-1);
xp_printf (XP_TEXT("%s"), ((xp_awk_node_var_t*)node)->id.name); xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name);
break; break;
case XP_AWK_NODE_NAMEDIDX: case XP_AWK_NDE_NAMEDIDX:
xp_assert (((xp_awk_node_idx_t*)node)->id.idxa == (xp_size_t)-1); xp_assert (((xp_awk_nde_idx_t*)nde)->id.idxa == (xp_size_t)-1);
xp_printf (XP_TEXT("%s["), ((xp_awk_node_idx_t*)node)->id.name); xp_printf (XP_TEXT("%s["), ((xp_awk_nde_idx_t*)nde)->id.name);
__print_expr_node (((xp_awk_node_idx_t*)node)->idx); __print_expr_nde (((xp_awk_nde_idx_t*)nde)->idx);
xp_printf (XP_TEXT("]")); xp_printf (XP_TEXT("]"));
break; break;
case XP_AWK_NODE_GLOBAL: case XP_AWK_NDE_GLOBAL:
if (((xp_awk_node_var_t*)node)->id.idxa != (xp_size_t)-1) { if (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1) {
xp_printf (XP_TEXT("__global%lu"), xp_printf (XP_TEXT("__global%lu"),
(unsigned long)((xp_awk_node_var_t*)node)->id.idxa); (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa);
} }
else { else {
xp_printf (XP_TEXT("%s"), ((xp_awk_node_var_t*)node)->id.name); xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name);
} }
break; break;
case XP_AWK_NODE_GLOBALIDX: case XP_AWK_NDE_GLOBALIDX:
if (((xp_awk_node_idx_t*)node)->id.idxa != (xp_size_t)-1) { if (((xp_awk_nde_idx_t*)nde)->id.idxa != (xp_size_t)-1) {
xp_printf (XP_TEXT("__global%lu["), xp_printf (XP_TEXT("__global%lu["),
(unsigned long)((xp_awk_node_idx_t*)node)->id.idxa); (unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa);
} }
else { else {
xp_printf (XP_TEXT("%s["), ((xp_awk_node_idx_t*)node)->id.name); xp_printf (XP_TEXT("%s["), ((xp_awk_nde_idx_t*)nde)->id.name);
} }
__print_expr_node (((xp_awk_node_idx_t*)node)->idx); __print_expr_nde (((xp_awk_nde_idx_t*)nde)->idx);
xp_printf (XP_TEXT("]")); xp_printf (XP_TEXT("]"));
break; break;
case XP_AWK_NODE_LOCAL: case XP_AWK_NDE_LOCAL:
if (((xp_awk_node_var_t*)node)->id.idxa != (xp_size_t)-1) { if (((xp_awk_nde_var_t*)nde)->id.idxa != (xp_size_t)-1) {
xp_printf (XP_TEXT("__local%lu"), xp_printf (XP_TEXT("__local%lu"),
(unsigned long)((xp_awk_node_var_t*)node)->id.idxa); (unsigned long)((xp_awk_nde_var_t*)nde)->id.idxa);
} }
else { else {
xp_printf (XP_TEXT("%s"), ((xp_awk_node_var_t*)node)->id.name); xp_printf (XP_TEXT("%s"), ((xp_awk_nde_var_t*)nde)->id.name);
} }
break; break;
case XP_AWK_NODE_LOCALIDX: case XP_AWK_NDE_LOCALIDX:
if (((xp_awk_node_idx_t*)node)->id.idxa != (xp_size_t)-1) { if (((xp_awk_nde_idx_t*)nde)->id.idxa != (xp_size_t)-1) {
xp_printf (XP_TEXT("__local%lu["), xp_printf (XP_TEXT("__local%lu["),
(unsigned long)((xp_awk_node_idx_t*)node)->id.idxa); (unsigned long)((xp_awk_nde_idx_t*)nde)->id.idxa);
} }
else { else {
xp_printf (XP_TEXT("%s["), ((xp_awk_node_idx_t*)node)->id.name); xp_printf (XP_TEXT("%s["), ((xp_awk_nde_idx_t*)nde)->id.name);
} }
__print_expr_node (((xp_awk_node_idx_t*)node)->idx); __print_expr_nde (((xp_awk_nde_idx_t*)nde)->idx);
xp_printf (XP_TEXT("]")); xp_printf (XP_TEXT("]"));
break; break;
case XP_AWK_NODE_POS: case XP_AWK_NDE_POS:
xp_printf (XP_TEXT("$")); xp_printf (XP_TEXT("$"));
__print_expr_node (((xp_awk_node_sgv_t*)node)->value); __print_expr_nde (((xp_awk_nde_sgv_t*)nde)->value);
break; break;
case XP_AWK_NODE_CALL: case XP_AWK_NDE_CALL:
xp_printf (XP_TEXT("%s ("), ((xp_awk_node_call_t*)node)->name); xp_printf (XP_TEXT("%s ("), ((xp_awk_nde_call_t*)nde)->name);
if (__print_expr_node_list (((xp_awk_node_call_t*)node)->args) == -1) return -1; if (__print_expr_nde_list (((xp_awk_nde_call_t*)nde)->args) == -1) return -1;
xp_printf (XP_TEXT(")")); xp_printf (XP_TEXT(")"));
break; break;
@ -161,12 +161,12 @@ static int __print_expr_node (xp_awk_node_t* node)
return 0; return 0;
} }
static int __print_expr_node_list (xp_awk_node_t* tree) static int __print_expr_nde_list (xp_awk_nde_t* tree)
{ {
xp_awk_node_t* p = tree; xp_awk_nde_t* p = tree;
while (p != XP_NULL) { while (p != XP_NULL) {
if (__print_expr_node (p) == -1) return -1; if (__print_expr_nde (p) == -1) return -1;
p = p->next; p = p->next;
if (p != XP_NULL) xp_printf (XP_TEXT(",")); if (p != XP_NULL) xp_printf (XP_TEXT(","));
} }
@ -174,171 +174,171 @@ static int __print_expr_node_list (xp_awk_node_t* tree)
return 0; return 0;
} }
static void __print_statements (xp_awk_node_t* tree, int depth) static void __print_statements (xp_awk_nde_t* tree, int depth)
{ {
xp_awk_node_t* p = tree; xp_awk_nde_t* p = tree;
xp_size_t i; xp_size_t i;
while (p != XP_NULL) { while (p != XP_NULL) {
switch (p->type) { switch (p->type) {
case XP_AWK_NODE_NULL: case XP_AWK_NDE_NULL:
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT(";\n")); xp_printf (XP_TEXT(";\n"));
break; break;
case XP_AWK_NODE_BLOCK: case XP_AWK_NDE_BLOCK:
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("{\n")); xp_printf (XP_TEXT("{\n"));
if (((xp_awk_node_block_t*)p)->nlocals > 0) { if (((xp_awk_nde_block_t*)p)->nlocals > 0) {
__print_tabs (depth + 1); __print_tabs (depth + 1);
xp_printf (XP_TEXT("local ")); xp_printf (XP_TEXT("local "));
for (i = 0; i < ((xp_awk_node_block_t*)p)->nlocals - 1; i++) { for (i = 0; i < ((xp_awk_nde_block_t*)p)->nlocals - 1; i++) {
xp_printf (XP_TEXT("__local%lu, "), (unsigned long)i); xp_printf (XP_TEXT("__local%lu, "), (unsigned long)i);
} }
xp_printf (XP_TEXT("__local%lu;\n"), (unsigned long)i); xp_printf (XP_TEXT("__local%lu;\n"), (unsigned long)i);
} }
__print_statements (((xp_awk_node_block_t*)p)->body, depth + 1); __print_statements (((xp_awk_nde_block_t*)p)->body, depth + 1);
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("}\n")); xp_printf (XP_TEXT("}\n"));
break; break;
case XP_AWK_NODE_IF: case XP_AWK_NDE_IF:
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("if (")); xp_printf (XP_TEXT("if ("));
__print_expr_node (((xp_awk_node_if_t*)p)->test); __print_expr_nde (((xp_awk_nde_if_t*)p)->test);
xp_printf (XP_TEXT(")\n")); xp_printf (XP_TEXT(")\n"));
xp_assert (((xp_awk_node_if_t*)p)->then_part != XP_NULL); xp_assert (((xp_awk_nde_if_t*)p)->then_part != XP_NULL);
if (((xp_awk_node_if_t*)p)->then_part->type == XP_AWK_NODE_BLOCK) if (((xp_awk_nde_if_t*)p)->then_part->type == XP_AWK_NDE_BLOCK)
__print_statements (((xp_awk_node_if_t*)p)->then_part, depth); __print_statements (((xp_awk_nde_if_t*)p)->then_part, depth);
else else
__print_statements (((xp_awk_node_if_t*)p)->then_part, depth + 1); __print_statements (((xp_awk_nde_if_t*)p)->then_part, depth + 1);
if (((xp_awk_node_if_t*)p)->else_part != XP_NULL) { if (((xp_awk_nde_if_t*)p)->else_part != XP_NULL) {
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("else\n")); xp_printf (XP_TEXT("else\n"));
if (((xp_awk_node_if_t*)p)->else_part->type == XP_AWK_NODE_BLOCK) if (((xp_awk_nde_if_t*)p)->else_part->type == XP_AWK_NDE_BLOCK)
__print_statements (((xp_awk_node_if_t*)p)->else_part, depth); __print_statements (((xp_awk_nde_if_t*)p)->else_part, depth);
else else
__print_statements (((xp_awk_node_if_t*)p)->else_part, depth + 1); __print_statements (((xp_awk_nde_if_t*)p)->else_part, depth + 1);
} }
break; break;
case XP_AWK_NODE_WHILE: case XP_AWK_NDE_WHILE:
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("while (")); xp_printf (XP_TEXT("while ("));
__print_expr_node (((xp_awk_node_while_t*)p)->test); __print_expr_nde (((xp_awk_nde_while_t*)p)->test);
xp_printf (XP_TEXT(")\n")); xp_printf (XP_TEXT(")\n"));
if (((xp_awk_node_while_t*)p)->body->type == XP_AWK_NODE_BLOCK) { if (((xp_awk_nde_while_t*)p)->body->type == XP_AWK_NDE_BLOCK) {
__print_statements (((xp_awk_node_while_t*)p)->body, depth); __print_statements (((xp_awk_nde_while_t*)p)->body, depth);
} }
else { else {
__print_statements (((xp_awk_node_while_t*)p)->body, depth + 1); __print_statements (((xp_awk_nde_while_t*)p)->body, depth + 1);
} }
break; break;
case XP_AWK_NODE_DOWHILE: case XP_AWK_NDE_DOWHILE:
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("do\n")); xp_printf (XP_TEXT("do\n"));
if (((xp_awk_node_while_t*)p)->body->type == XP_AWK_NODE_BLOCK) { if (((xp_awk_nde_while_t*)p)->body->type == XP_AWK_NDE_BLOCK) {
__print_statements (((xp_awk_node_while_t*)p)->body, depth); __print_statements (((xp_awk_nde_while_t*)p)->body, depth);
} }
else { else {
__print_statements (((xp_awk_node_while_t*)p)->body, depth + 1); __print_statements (((xp_awk_nde_while_t*)p)->body, depth + 1);
} }
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("while (")); xp_printf (XP_TEXT("while ("));
__print_expr_node (((xp_awk_node_while_t*)p)->test); __print_expr_nde (((xp_awk_nde_while_t*)p)->test);
xp_printf (XP_TEXT(");\n")); xp_printf (XP_TEXT(");\n"));
break; break;
case XP_AWK_NODE_FOR: case XP_AWK_NDE_FOR:
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("for (")); xp_printf (XP_TEXT("for ("));
if (((xp_awk_node_for_t*)p)->init != XP_NULL) { if (((xp_awk_nde_for_t*)p)->init != XP_NULL) {
__print_expr_node (((xp_awk_node_for_t*)p)->init); __print_expr_nde (((xp_awk_nde_for_t*)p)->init);
} }
xp_printf (XP_TEXT("; ")); xp_printf (XP_TEXT("; "));
if (((xp_awk_node_for_t*)p)->test != XP_NULL) { if (((xp_awk_nde_for_t*)p)->test != XP_NULL) {
__print_expr_node (((xp_awk_node_for_t*)p)->test); __print_expr_nde (((xp_awk_nde_for_t*)p)->test);
} }
xp_printf (XP_TEXT("; ")); xp_printf (XP_TEXT("; "));
if (((xp_awk_node_for_t*)p)->incr != XP_NULL) { if (((xp_awk_nde_for_t*)p)->incr != XP_NULL) {
__print_expr_node (((xp_awk_node_for_t*)p)->incr); __print_expr_nde (((xp_awk_nde_for_t*)p)->incr);
} }
xp_printf (XP_TEXT(")\n")); xp_printf (XP_TEXT(")\n"));
if (((xp_awk_node_for_t*)p)->body->type == XP_AWK_NODE_BLOCK) { if (((xp_awk_nde_for_t*)p)->body->type == XP_AWK_NDE_BLOCK) {
__print_statements (((xp_awk_node_for_t*)p)->body, depth); __print_statements (((xp_awk_nde_for_t*)p)->body, depth);
} }
else { else {
__print_statements (((xp_awk_node_for_t*)p)->body, depth + 1); __print_statements (((xp_awk_nde_for_t*)p)->body, depth + 1);
} }
case XP_AWK_NODE_BREAK: case XP_AWK_NDE_BREAK:
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("break;\n")); xp_printf (XP_TEXT("break;\n"));
break; break;
case XP_AWK_NODE_CONTINUE: case XP_AWK_NDE_CONTINUE:
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("continue;\n")); xp_printf (XP_TEXT("continue;\n"));
break; break;
case XP_AWK_NODE_RETURN: case XP_AWK_NDE_RETURN:
__print_tabs (depth); __print_tabs (depth);
if (((xp_awk_node_sgv_t*)p)->value == XP_NULL) { if (((xp_awk_nde_sgv_t*)p)->value == XP_NULL) {
xp_printf (XP_TEXT("return;\n")); xp_printf (XP_TEXT("return;\n"));
} }
else { else {
xp_printf (XP_TEXT("return ")); xp_printf (XP_TEXT("return "));
xp_assert (((xp_awk_node_sgv_t*)p)->value->next == XP_NULL); xp_assert (((xp_awk_nde_sgv_t*)p)->value->next == XP_NULL);
if (__print_expr_node(((xp_awk_node_sgv_t*)p)->value) == 0) { if (__print_expr_nde(((xp_awk_nde_sgv_t*)p)->value) == 0) {
xp_printf (XP_TEXT(";\n")); xp_printf (XP_TEXT(";\n"));
} }
else { else {
xp_awk_node_sgv_t* x = (xp_awk_node_sgv_t*)p; xp_awk_nde_sgv_t* x = (xp_awk_nde_sgv_t*)p;
xp_printf (XP_TEXT("***INTERNAL ERROR: unknown node type - %d\n"), x->type); xp_printf (XP_TEXT("***INTERNAL ERROR: unknown nde type - %d\n"), x->type);
} }
} }
break; break;
case XP_AWK_NODE_EXIT: case XP_AWK_NDE_EXIT:
__print_tabs (depth); __print_tabs (depth);
if (((xp_awk_node_sgv_t*)p)->value == XP_NULL) { if (((xp_awk_nde_sgv_t*)p)->value == XP_NULL) {
xp_printf (XP_TEXT("exit;\n")); xp_printf (XP_TEXT("exit;\n"));
} }
else { else {
xp_printf (XP_TEXT("exit ")); xp_printf (XP_TEXT("exit "));
xp_assert (((xp_awk_node_sgv_t*)p)->value->next == XP_NULL); xp_assert (((xp_awk_nde_sgv_t*)p)->value->next == XP_NULL);
if (__print_expr_node(((xp_awk_node_sgv_t*)p)->value) == 0) { if (__print_expr_nde(((xp_awk_nde_sgv_t*)p)->value) == 0) {
xp_printf (XP_TEXT(";\n")); xp_printf (XP_TEXT(";\n"));
} }
else { else {
xp_awk_node_sgv_t* x = (xp_awk_node_sgv_t*)p; xp_awk_nde_sgv_t* x = (xp_awk_nde_sgv_t*)p;
xp_printf (XP_TEXT("***INTERNAL ERROR: unknown node type - %d\n"), x->type); xp_printf (XP_TEXT("***INTERNAL ERROR: unknown nde type - %d\n"), x->type);
} }
} }
break; break;
case XP_AWK_NODE_NEXT: case XP_AWK_NDE_NEXT:
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("next;\n")); xp_printf (XP_TEXT("next;\n"));
break; break;
case XP_AWK_NODE_NEXTFILE: case XP_AWK_NDE_NEXTFILE:
__print_tabs (depth); __print_tabs (depth);
xp_printf (XP_TEXT("nextfile;\n")); xp_printf (XP_TEXT("nextfile;\n"));
break; break;
default: default:
__print_tabs (depth); __print_tabs (depth);
if (__print_expr_node(p) == 0) { if (__print_expr_nde(p) == 0) {
xp_printf (XP_TEXT(";\n")); xp_printf (XP_TEXT(";\n"));
} }
else { else {
@ -350,126 +350,126 @@ static void __print_statements (xp_awk_node_t* tree, int depth)
} }
} }
void xp_awk_prnpt (xp_awk_node_t* tree) void xp_awk_prnpt (xp_awk_nde_t* tree)
{ {
__print_statements (tree, 0); __print_statements (tree, 0);
} }
void xp_awk_clrpt (xp_awk_node_t* tree) void xp_awk_clrpt (xp_awk_nde_t* tree)
{ {
xp_awk_node_t* p = tree; xp_awk_nde_t* p = tree;
xp_awk_node_t* next; xp_awk_nde_t* next;
while (p != XP_NULL) { while (p != XP_NULL) {
next = p->next; next = p->next;
switch (p->type) { switch (p->type) {
case XP_AWK_NODE_NULL: case XP_AWK_NDE_NULL:
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_BLOCK: case XP_AWK_NDE_BLOCK:
xp_awk_clrpt (((xp_awk_node_block_t*)p)->body); xp_awk_clrpt (((xp_awk_nde_block_t*)p)->body);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_IF: case XP_AWK_NDE_IF:
xp_awk_clrpt (((xp_awk_node_if_t*)p)->test); xp_awk_clrpt (((xp_awk_nde_if_t*)p)->test);
xp_awk_clrpt (((xp_awk_node_if_t*)p)->then_part); xp_awk_clrpt (((xp_awk_nde_if_t*)p)->then_part);
if (((xp_awk_node_if_t*)p)->else_part != XP_NULL) if (((xp_awk_nde_if_t*)p)->else_part != XP_NULL)
xp_awk_clrpt (((xp_awk_node_if_t*)p)->else_part); xp_awk_clrpt (((xp_awk_nde_if_t*)p)->else_part);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_WHILE: case XP_AWK_NDE_WHILE:
case XP_AWK_NODE_DOWHILE: case XP_AWK_NDE_DOWHILE:
xp_awk_clrpt (((xp_awk_node_while_t*)p)->test); xp_awk_clrpt (((xp_awk_nde_while_t*)p)->test);
xp_awk_clrpt (((xp_awk_node_while_t*)p)->body); xp_awk_clrpt (((xp_awk_nde_while_t*)p)->body);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_FOR: case XP_AWK_NDE_FOR:
if (((xp_awk_node_for_t*)p)->init != XP_NULL) if (((xp_awk_nde_for_t*)p)->init != XP_NULL)
xp_awk_clrpt (((xp_awk_node_for_t*)p)->init); xp_awk_clrpt (((xp_awk_nde_for_t*)p)->init);
if (((xp_awk_node_for_t*)p)->test != XP_NULL) if (((xp_awk_nde_for_t*)p)->test != XP_NULL)
xp_awk_clrpt (((xp_awk_node_for_t*)p)->test); xp_awk_clrpt (((xp_awk_nde_for_t*)p)->test);
if (((xp_awk_node_for_t*)p)->incr != XP_NULL) if (((xp_awk_nde_for_t*)p)->incr != XP_NULL)
xp_awk_clrpt (((xp_awk_node_for_t*)p)->incr); xp_awk_clrpt (((xp_awk_nde_for_t*)p)->incr);
xp_awk_clrpt (((xp_awk_node_for_t*)p)->body); xp_awk_clrpt (((xp_awk_nde_for_t*)p)->body);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_BREAK: case XP_AWK_NDE_BREAK:
case XP_AWK_NODE_CONTINUE: case XP_AWK_NDE_CONTINUE:
case XP_AWK_NODE_NEXT: case XP_AWK_NDE_NEXT:
case XP_AWK_NODE_NEXTFILE: case XP_AWK_NDE_NEXTFILE:
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_RETURN: case XP_AWK_NDE_RETURN:
case XP_AWK_NODE_EXIT: case XP_AWK_NDE_EXIT:
if (((xp_awk_node_sgv_t*)p)->value != XP_NULL) if (((xp_awk_nde_sgv_t*)p)->value != XP_NULL)
xp_awk_clrpt (((xp_awk_node_sgv_t*)p)->value); xp_awk_clrpt (((xp_awk_nde_sgv_t*)p)->value);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_ASSIGN: case XP_AWK_NDE_ASS:
xp_awk_clrpt (((xp_awk_node_assign_t*)p)->left); xp_awk_clrpt (((xp_awk_nde_ass_t*)p)->left);
xp_awk_clrpt (((xp_awk_node_assign_t*)p)->right); xp_awk_clrpt (((xp_awk_nde_ass_t*)p)->right);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_BINARY: case XP_AWK_NDE_BINARY:
xp_assert ((((xp_awk_node_expr_t*)p)->left)->next == XP_NULL); xp_assert ((((xp_awk_nde_expr_t*)p)->left)->next == XP_NULL);
xp_assert ((((xp_awk_node_expr_t*)p)->right)->next == XP_NULL); xp_assert ((((xp_awk_nde_expr_t*)p)->right)->next == XP_NULL);
xp_awk_clrpt (((xp_awk_node_expr_t*)p)->left); xp_awk_clrpt (((xp_awk_nde_expr_t*)p)->left);
xp_awk_clrpt (((xp_awk_node_expr_t*)p)->right); xp_awk_clrpt (((xp_awk_nde_expr_t*)p)->right);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_UNARY: case XP_AWK_NDE_UNARY:
// TODO: clear unary expression... // TODO: clear unary expression...
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_STR: case XP_AWK_NDE_STR:
case XP_AWK_NODE_NUM: case XP_AWK_NDE_NUM:
xp_free (((xp_awk_node_term_t*)p)->value); xp_free (((xp_awk_nde_term_t*)p)->value);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_NAMED: case XP_AWK_NDE_NAMED:
xp_assert (((xp_awk_node_idx_t*)p)->id.name != XP_NULL); xp_assert (((xp_awk_nde_idx_t*)p)->id.name != XP_NULL);
case XP_AWK_NODE_GLOBAL: case XP_AWK_NDE_GLOBAL:
case XP_AWK_NODE_LOCAL: case XP_AWK_NDE_LOCAL:
case XP_AWK_NODE_ARG: case XP_AWK_NDE_ARG:
if (((xp_awk_node_var_t*)p)->id.name != XP_NULL) if (((xp_awk_nde_var_t*)p)->id.name != XP_NULL)
xp_free (((xp_awk_node_var_t*)p)->id.name); xp_free (((xp_awk_nde_var_t*)p)->id.name);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_NAMEDIDX: case XP_AWK_NDE_NAMEDIDX:
xp_assert (((xp_awk_node_idx_t*)p)->id.name != XP_NULL); xp_assert (((xp_awk_nde_idx_t*)p)->id.name != XP_NULL);
case XP_AWK_NODE_GLOBALIDX: case XP_AWK_NDE_GLOBALIDX:
case XP_AWK_NODE_LOCALIDX: case XP_AWK_NDE_LOCALIDX:
case XP_AWK_NODE_ARGIDX: case XP_AWK_NDE_ARGIDX:
xp_awk_clrpt (((xp_awk_node_idx_t*)p)->idx); xp_awk_clrpt (((xp_awk_nde_idx_t*)p)->idx);
if (((xp_awk_node_idx_t*)p)->id.name != XP_NULL) if (((xp_awk_nde_idx_t*)p)->id.name != XP_NULL)
xp_free (((xp_awk_node_idx_t*)p)->id.name); xp_free (((xp_awk_nde_idx_t*)p)->id.name);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_POS: case XP_AWK_NDE_POS:
xp_assert (((xp_awk_node_sgv_t*)p)->value != XP_NULL); xp_assert (((xp_awk_nde_sgv_t*)p)->value != XP_NULL);
xp_awk_clrpt (((xp_awk_node_sgv_t*)p)->value); xp_awk_clrpt (((xp_awk_nde_sgv_t*)p)->value);
xp_free (p); xp_free (p);
break; break;
case XP_AWK_NODE_CALL: case XP_AWK_NDE_CALL:
xp_free (((xp_awk_node_call_t*)p)->name); xp_free (((xp_awk_nde_call_t*)p)->name);
xp_awk_clrpt (((xp_awk_node_call_t*)p)->args); xp_awk_clrpt (((xp_awk_nde_call_t*)p)->args);
xp_free (p); xp_free (p);
break; break;

View File

@ -1,167 +1,171 @@
/* /*
* $Id: tree.h,v 1.22 2006-02-05 16:00:33 bacon Exp $ * $Id: tree.h,v 1.23 2006-03-03 11:45:45 bacon Exp $
*/ */
#ifndef _XP_AWK_TREE_H_ #ifndef _XP_AWK_TREE_H_
#define _XP_AWK_TREE_H_ #define _XP_AWK_TREE_H_
#ifndef _XP_AWK_AWK_H_
#error Never include this file directly. Include <xp/aw/awk.h> instead
#endif
enum enum
{ {
XP_AWK_NODE_NULL, XP_AWK_NDE_NULL,
XP_AWK_NODE_BLOCK, XP_AWK_NDE_BLOCK,
XP_AWK_NODE_BREAK, XP_AWK_NDE_BREAK,
XP_AWK_NODE_CONTINUE, XP_AWK_NDE_CONTINUE,
XP_AWK_NODE_RETURN, XP_AWK_NDE_RETURN,
XP_AWK_NODE_EXIT, XP_AWK_NDE_EXIT,
XP_AWK_NODE_NEXT, XP_AWK_NDE_NEXT,
XP_AWK_NODE_NEXTFILE, XP_AWK_NDE_NEXTFILE,
XP_AWK_NODE_ASSIGN, XP_AWK_NDE_ASS,
XP_AWK_NODE_BINARY, XP_AWK_NDE_BINARY,
XP_AWK_NODE_UNARY, XP_AWK_NDE_UNARY,
XP_AWK_NODE_STR, XP_AWK_NDE_STR,
XP_AWK_NODE_NUM, XP_AWK_NDE_NUM,
XP_AWK_NODE_NAMED, XP_AWK_NDE_NAMED,
XP_AWK_NODE_NAMEDIDX, XP_AWK_NDE_NAMEDIDX,
XP_AWK_NODE_GLOBAL, XP_AWK_NDE_GLOBAL,
XP_AWK_NODE_GLOBALIDX, XP_AWK_NDE_GLOBALIDX,
XP_AWK_NODE_LOCAL, XP_AWK_NDE_LOCAL,
XP_AWK_NODE_LOCALIDX, XP_AWK_NDE_LOCALIDX,
XP_AWK_NODE_ARG, XP_AWK_NDE_ARG,
XP_AWK_NODE_ARGIDX, XP_AWK_NDE_ARGIDX,
XP_AWK_NODE_POS, XP_AWK_NDE_POS,
XP_AWK_NODE_CALL, XP_AWK_NDE_CALL,
XP_AWK_NODE_IF, XP_AWK_NDE_IF,
XP_AWK_NODE_WHILE, XP_AWK_NDE_WHILE,
XP_AWK_NODE_DOWHILE, XP_AWK_NDE_DOWHILE,
XP_AWK_NODE_FOR XP_AWK_NDE_FOR
}; };
typedef struct xp_awk_func_t xp_awk_func_t; typedef struct xp_awk_func_t xp_awk_func_t;
typedef struct xp_awk_node_t xp_awk_node_t; typedef struct xp_awk_nde_t xp_awk_nde_t;
typedef struct xp_awk_node_sgv_t xp_awk_node_sgv_t; typedef struct xp_awk_nde_sgv_t xp_awk_nde_sgv_t;
typedef struct xp_awk_node_block_t xp_awk_node_block_t; typedef struct xp_awk_nde_block_t xp_awk_nde_block_t;
typedef struct xp_awk_node_assign_t xp_awk_node_assign_t; typedef struct xp_awk_nde_ass_t xp_awk_nde_ass_t;
typedef struct xp_awk_node_expr_t xp_awk_node_expr_t; typedef struct xp_awk_nde_expr_t xp_awk_nde_expr_t;
typedef struct xp_awk_node_term_t xp_awk_node_term_t; typedef struct xp_awk_nde_term_t xp_awk_nde_term_t;
typedef struct xp_awk_node_var_t xp_awk_node_var_t; typedef struct xp_awk_nde_var_t xp_awk_nde_var_t;
typedef struct xp_awk_node_idx_t xp_awk_node_idx_t; typedef struct xp_awk_nde_idx_t xp_awk_nde_idx_t;
typedef struct xp_awk_node_pos_t xp_awk_node_pos_t; typedef struct xp_awk_nde_pos_t xp_awk_nde_pos_t;
typedef struct xp_awk_node_call_t xp_awk_node_call_t; typedef struct xp_awk_nde_call_t xp_awk_nde_call_t;
typedef struct xp_awk_node_if_t xp_awk_node_if_t; typedef struct xp_awk_nde_if_t xp_awk_nde_if_t;
typedef struct xp_awk_node_while_t xp_awk_node_while_t; typedef struct xp_awk_nde_while_t xp_awk_nde_while_t;
typedef struct xp_awk_node_for_t xp_awk_node_for_t; typedef struct xp_awk_nde_for_t xp_awk_nde_for_t;
struct xp_awk_func_t struct xp_awk_func_t
{ {
xp_char_t* name; xp_char_t* name;
xp_size_t nargs; xp_size_t nargs;
xp_awk_node_t* body; xp_awk_nde_t* body;
}; };
#define XP_AWK_NODE_HDR \ #define XP_AWK_NDE_HDR \
int type; \ int type; \
xp_awk_node_t* next xp_awk_nde_t* next
struct xp_awk_node_t struct xp_awk_nde_t
{ {
XP_AWK_NODE_HDR; XP_AWK_NDE_HDR;
}; };
/* XP_AWK_NODE_RETURN, XP_AWK_NODE_EXIT, XP_AWK_NODE_POS */ /* XP_AWK_NDE_RETURN, XP_AWK_NDE_EXIT, XP_AWK_NDE_POS */
struct xp_awk_node_sgv_t struct xp_awk_nde_sgv_t
{ {
XP_AWK_NODE_HDR; XP_AWK_NDE_HDR;
xp_awk_node_t* value; xp_awk_nde_t* value;
}; };
struct xp_awk_node_block_t struct xp_awk_nde_block_t
{ {
XP_AWK_NODE_HDR; XP_AWK_NDE_HDR;
xp_size_t nlocals; xp_size_t nlocals;
xp_awk_node_t* body; xp_awk_nde_t* body;
}; };
struct xp_awk_node_assign_t struct xp_awk_nde_ass_t
{ {
XP_AWK_NODE_HDR; XP_AWK_NDE_HDR;
xp_awk_node_t* left; xp_awk_nde_t* left;
xp_awk_node_t* right; xp_awk_nde_t* right;
}; };
struct xp_awk_node_expr_t struct xp_awk_nde_expr_t
{ {
XP_AWK_NODE_HDR; XP_AWK_NDE_HDR;
int opcode; int opcode;
xp_awk_node_t* left; xp_awk_nde_t* left;
xp_awk_node_t* right; xp_awk_nde_t* right;
}; };
struct xp_awk_node_term_t struct xp_awk_nde_term_t
{ {
XP_AWK_NODE_HDR; XP_AWK_NDE_HDR;
xp_char_t* value; xp_char_t* value;
}; };
struct xp_awk_node_var_t struct xp_awk_nde_var_t
{ {
XP_AWK_NODE_HDR; XP_AWK_NDE_HDR;
struct // uniion
{
xp_char_t* name;
xp_size_t idxa;
} id;
};
struct xp_awk_node_idx_t
{
XP_AWK_NODE_HDR;
struct // union struct // union
{ {
xp_char_t* name; xp_char_t* name;
xp_size_t idxa; xp_size_t idxa;
} id; } id;
xp_awk_node_t* idx; };
struct xp_awk_nde_idx_t
{
XP_AWK_NDE_HDR;
struct // union
{
xp_char_t* name;
xp_size_t idxa;
} id;
xp_awk_nde_t* idx;
}; };
struct xp_awk_node_call_t struct xp_awk_nde_call_t
{ {
XP_AWK_NODE_HDR; /* XP_AWK_NODE_CALL */ XP_AWK_NDE_HDR; /* XP_AWK_NDE_CALL */
xp_char_t* name; xp_char_t* name;
xp_awk_node_t* args; xp_awk_nde_t* args;
}; };
struct xp_awk_node_if_t struct xp_awk_nde_if_t
{ {
XP_AWK_NODE_HDR; /* XP_AWK_NODE_IF */ XP_AWK_NDE_HDR; /* XP_AWK_NDE_IF */
xp_awk_node_t* test; xp_awk_nde_t* test;
xp_awk_node_t* then_part; xp_awk_nde_t* then_part;
xp_awk_node_t* else_part; /* optional */ xp_awk_nde_t* else_part; /* optional */
}; };
struct xp_awk_node_while_t struct xp_awk_nde_while_t
{ {
XP_AWK_NODE_HDR; /* XP_AWK_NODE_WHILE, XP_AWK_NODE_DOWHILE */ XP_AWK_NDE_HDR; /* XP_AWK_NDE_WHILE, XP_AWK_NDE_DOWHILE */
xp_awk_node_t* test; xp_awk_nde_t* test;
xp_awk_node_t* body; xp_awk_nde_t* body;
}; };
struct xp_awk_node_for_t struct xp_awk_nde_for_t
{ {
XP_AWK_NODE_HDR; /* XP_AWK_NODE_FOR */ XP_AWK_NDE_HDR; /* XP_AWK_NDE_FOR */
xp_awk_node_t* init; /* optional */ xp_awk_nde_t* init; /* optional */
xp_awk_node_t* test; /* optional */ xp_awk_nde_t* test; /* optional */
xp_awk_node_t* incr; /* optional */ xp_awk_nde_t* incr; /* optional */
xp_awk_node_t* body; xp_awk_nde_t* body;
}; };
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void xp_awk_prnpt (xp_awk_node_t* tree); void xp_awk_prnpt (xp_awk_nde_t* tree);
void xp_awk_clrpt (xp_awk_node_t* tree); void xp_awk_clrpt (xp_awk_nde_t* tree);
#ifdef __cplusplus #ifdef __cplusplus
} }

44
ase/awk/val.h Normal file
View File

@ -0,0 +1,44 @@
/*
* $Id: val.h,v 1.1 2006-03-03 11:45:45 bacon Exp $
*/
#ifndef _XP_AWK_VAL_H_
#define _XP_AWK_VAL_H_
#ifndef _XP_AWK_AWK_H_
#error Never include this file directly. Include <xp/awk/awk.h> instead
#endif
typedef struct xp_awk_val_t xp_awk_val_t;
typedef struct xp_awk_val_int_t xp_awk_val_int_t;
typedef struct xp_awk_val_real_t xp_awk_val_real_t;
typedef struct xp_awk_val_str_t xp_awk_val_str_t;
#define XP_AWK_VAL_HDR \
int type
struct xp_awk_val_t
{
XP_AWK_VAL_HDR;
};
struct xp_awk_val_int_t
{
XP_AWK_VAL_HDR;
xp_long_t val;
};
struct xp_awk_val_real_t
{
XP_AWK_VAL_HDR;
xp_real_t val;
};
struct xp_awk_val_str_t
{
XP_AWK_VAL_HDR;
xp_char_t* buf;
xp_size_t len;
};
#endif