qse/ase/awk/tree.h

362 lines
6.9 KiB
C
Raw Normal View History

2006-01-09 12:51:47 +00:00
/*
2006-07-14 05:21:30 +00:00
* $Id: tree.h,v 1.60 2006-07-14 05:21:30 bacon Exp $
2006-01-09 12:51:47 +00:00
*/
2006-01-02 16:38:23 +00:00
2006-01-09 12:51:47 +00:00
#ifndef _XP_AWK_TREE_H_
#define _XP_AWK_TREE_H_
2006-03-03 11:45:45 +00:00
#ifndef _XP_AWK_AWK_H_
2006-03-03 11:51:48 +00:00
#error Never include this file directly. Include <xp/awk/awk.h> instead
2006-03-03 11:45:45 +00:00
#endif
2006-01-09 12:51:47 +00:00
enum
{
2006-03-03 11:45:45 +00:00
XP_AWK_NDE_NULL,
2006-03-04 15:54:37 +00:00
2006-04-07 16:52:42 +00:00
/* statement */
2006-03-05 17:07:33 +00:00
XP_AWK_NDE_BLK,
2006-04-07 16:52:42 +00:00
XP_AWK_NDE_IF,
XP_AWK_NDE_WHILE,
XP_AWK_NDE_DOWHILE,
XP_AWK_NDE_FOR,
2006-04-29 12:09:29 +00:00
XP_AWK_NDE_FOREACH,
2006-04-07 16:52:42 +00:00
XP_AWK_NDE_BREAK,
XP_AWK_NDE_CONTINUE,
XP_AWK_NDE_RETURN,
XP_AWK_NDE_EXIT,
XP_AWK_NDE_NEXT,
XP_AWK_NDE_NEXTFILE,
2006-06-27 14:18:19 +00:00
XP_AWK_NDE_DELETE,
XP_AWK_NDE_PRINT,
2006-03-05 17:07:33 +00:00
2006-04-07 16:52:42 +00:00
/* expression */
2006-04-14 16:26:00 +00:00
/* if you change the following values including their order,
* you should change __eval_func of __eval_expression
* in run.c accordingly */
2006-04-24 15:36:08 +00:00
XP_AWK_NDE_GRP,
2006-04-07 16:52:42 +00:00
XP_AWK_NDE_ASS,
2006-03-04 15:54:37 +00:00
XP_AWK_NDE_EXP_BIN,
XP_AWK_NDE_EXP_UNR,
2006-04-02 12:45:04 +00:00
XP_AWK_NDE_EXP_INCPRE,
XP_AWK_NDE_EXP_INCPST,
2006-04-11 09:16:20 +00:00
XP_AWK_NDE_CND,
2006-06-19 15:43:27 +00:00
XP_AWK_NDE_BFN,
2006-07-14 04:19:22 +00:00
XP_AWK_NDE_AFN,
2006-03-05 17:07:33 +00:00
XP_AWK_NDE_INT,
2006-03-28 16:33:09 +00:00
XP_AWK_NDE_REAL,
2006-03-03 11:45:45 +00:00
XP_AWK_NDE_STR,
2006-04-24 11:26:00 +00:00
XP_AWK_NDE_REX,
2006-03-03 11:45:45 +00:00
XP_AWK_NDE_NAMED,
XP_AWK_NDE_GLOBAL,
XP_AWK_NDE_LOCAL,
XP_AWK_NDE_ARG,
2006-04-07 16:52:42 +00:00
XP_AWK_NDE_NAMEDIDX,
XP_AWK_NDE_GLOBALIDX,
XP_AWK_NDE_LOCALIDX,
2006-03-03 11:45:45 +00:00
XP_AWK_NDE_ARGIDX,
2006-06-12 15:11:02 +00:00
XP_AWK_NDE_POS,
2006-06-13 08:35:53 +00:00
XP_AWK_NDE_GETLINE,
};
2006-06-13 15:11:39 +00:00
enum
{
2006-06-28 10:40:24 +00:00
/* the order of these values match
* __in_type_map and __in_opt_map in extio.c */
XP_AWK_IN_PIPE,
XP_AWK_IN_COPROC,
2006-06-29 14:38:01 +00:00
XP_AWK_IN_FILE,
XP_AWK_IN_CONSOLE
2006-06-13 15:11:39 +00:00
};
2006-06-13 08:35:53 +00:00
enum
{
2006-06-28 03:44:40 +00:00
/* the order of these values match
* __out_type_map and __out_opt_map in extio.c */
XP_AWK_OUT_PIPE,
XP_AWK_OUT_COPROC,
XP_AWK_OUT_FILE,
XP_AWK_OUT_FILE_APPEND,
XP_AWK_OUT_CONSOLE
2006-01-09 12:51:47 +00:00
};
2006-07-13 15:43:39 +00:00
/* afn (awk function defined with the keyword function) */
2006-06-20 15:27:50 +00:00
typedef struct xp_awk_afn_t xp_awk_afn_t;
2006-01-30 14:34:47 +00:00
2006-03-04 15:54:37 +00:00
typedef struct xp_awk_nde_t xp_awk_nde_t;
2006-03-05 17:07:33 +00:00
typedef struct xp_awk_nde_blk_t xp_awk_nde_blk_t;
2006-04-24 15:36:08 +00:00
typedef struct xp_awk_nde_grp_t xp_awk_nde_grp_t;
2006-03-04 15:54:37 +00:00
typedef struct xp_awk_nde_ass_t xp_awk_nde_ass_t;
typedef struct xp_awk_nde_exp_t xp_awk_nde_exp_t;
2006-04-11 09:16:20 +00:00
typedef struct xp_awk_nde_cnd_t xp_awk_nde_cnd_t;
2006-03-05 17:07:33 +00:00
typedef struct xp_awk_nde_pos_t xp_awk_nde_pos_t;
typedef struct xp_awk_nde_int_t xp_awk_nde_int_t;
2006-03-28 16:33:09 +00:00
typedef struct xp_awk_nde_real_t xp_awk_nde_real_t;
2006-03-05 17:07:33 +00:00
typedef struct xp_awk_nde_str_t xp_awk_nde_str_t;
2006-04-24 11:26:00 +00:00
typedef struct xp_awk_nde_rex_t xp_awk_nde_rex_t;
2006-03-04 15:54:37 +00:00
typedef struct xp_awk_nde_var_t xp_awk_nde_var_t;
typedef struct xp_awk_nde_call_t xp_awk_nde_call_t;
2006-06-12 15:11:02 +00:00
typedef struct xp_awk_nde_getline_t xp_awk_nde_getline_t;
2006-03-04 15:54:37 +00:00
typedef struct xp_awk_nde_if_t xp_awk_nde_if_t;
typedef struct xp_awk_nde_while_t xp_awk_nde_while_t;
typedef struct xp_awk_nde_for_t xp_awk_nde_for_t;
2006-04-29 12:09:29 +00:00
typedef struct xp_awk_nde_foreach_t xp_awk_nde_foreach_t;
2006-03-04 15:54:37 +00:00
typedef struct xp_awk_nde_break_t xp_awk_nde_break_t;
typedef struct xp_awk_nde_continue_t xp_awk_nde_continue_t;
typedef struct xp_awk_nde_return_t xp_awk_nde_return_t;
typedef struct xp_awk_nde_exit_t xp_awk_nde_exit_t;
2006-04-22 16:16:40 +00:00
typedef struct xp_awk_nde_next_t xp_awk_nde_next_t;
typedef struct xp_awk_nde_nextfile_t xp_awk_nde_nextfile_t;
2006-06-27 14:18:19 +00:00
typedef struct xp_awk_nde_delete_t xp_awk_nde_delete_t;
typedef struct xp_awk_nde_print_t xp_awk_nde_print_t;
2006-01-09 12:51:47 +00:00
2006-06-20 15:27:50 +00:00
struct xp_awk_afn_t
2006-01-22 15:11:17 +00:00
{
xp_char_t* name;
xp_size_t nargs;
2006-03-03 11:45:45 +00:00
xp_awk_nde_t* body;
2006-01-22 15:11:17 +00:00
};
2006-03-03 11:45:45 +00:00
#define XP_AWK_NDE_HDR \
2006-01-09 12:51:47 +00:00
int type; \
2006-03-03 11:45:45 +00:00
xp_awk_nde_t* next
2006-01-09 12:51:47 +00:00
2006-03-03 11:45:45 +00:00
struct xp_awk_nde_t
2006-01-09 12:51:47 +00:00
{
2006-03-03 11:45:45 +00:00
XP_AWK_NDE_HDR;
2006-01-09 12:51:47 +00:00
};
2006-03-05 17:07:33 +00:00
/* XP_AWK_NDE_BLK - block statement including top-level blocks */
struct xp_awk_nde_blk_t
2006-01-09 12:51:47 +00:00
{
2006-03-03 11:45:45 +00:00
XP_AWK_NDE_HDR;
2006-02-04 19:31:51 +00:00
xp_size_t nlocals;
2006-03-03 11:45:45 +00:00
xp_awk_nde_t* body;
2006-01-09 12:51:47 +00:00
};
2006-04-24 15:36:08 +00:00
/* XP_AWK_NDE_GRP - expression group */
struct xp_awk_nde_grp_t
{
XP_AWK_NDE_HDR;
2006-04-26 15:53:17 +00:00
xp_awk_nde_t* body;
2006-04-24 15:36:08 +00:00
};
2006-03-04 15:54:37 +00:00
/* XP_AWK_NDE_ASS - assignment */
2006-03-03 11:45:45 +00:00
struct xp_awk_nde_ass_t
2006-01-11 14:03:17 +00:00
{
2006-03-03 11:45:45 +00:00
XP_AWK_NDE_HDR;
2006-04-14 16:26:00 +00:00
int opcode;
2006-03-03 11:45:45 +00:00
xp_awk_nde_t* left;
xp_awk_nde_t* right;
2006-01-11 14:03:17 +00:00
};
2006-04-02 12:45:04 +00:00
/* XP_AWK_NDE_EXP_BIN, XP_AWK_NDE_EXP_UNR,
2006-04-11 09:16:20 +00:00
* XP_AWK_NDE_EXP_INCPRE, XP_AW_NDE_EXP_INCPST */
2006-03-04 15:54:37 +00:00
struct xp_awk_nde_exp_t
2006-01-10 13:57:54 +00:00
{
2006-03-03 11:45:45 +00:00
XP_AWK_NDE_HDR;
2006-01-11 14:03:17 +00:00
int opcode;
2006-03-03 11:45:45 +00:00
xp_awk_nde_t* left;
2006-04-02 12:45:04 +00:00
xp_awk_nde_t* right; /* XP_NULL for UNR, INCPRE, INCPST */
2006-01-10 13:57:54 +00:00
};
2006-04-11 09:16:20 +00:00
/* XP_AWK_NDE_CND */
struct xp_awk_nde_cnd_t
{
XP_AWK_NDE_HDR;
xp_awk_nde_t* test;
xp_awk_nde_t* left;
xp_awk_nde_t* right;
};
2006-03-05 17:07:33 +00:00
/* XP_AWK_NDE_POS - positional - $1, $2, $x, etc */
struct xp_awk_nde_pos_t
{
XP_AWK_NDE_HDR;
xp_awk_nde_t* val;
};
/* XP_AWK_NDE_INT */
struct xp_awk_nde_int_t
{
XP_AWK_NDE_HDR;
xp_long_t val;
};
2006-03-28 16:33:09 +00:00
/* XP_AWK_NDE_REAL */
struct xp_awk_nde_real_t
{
XP_AWK_NDE_HDR;
xp_real_t val;
};
2006-03-05 17:07:33 +00:00
/* XP_AWK_NDE_STR */
struct xp_awk_nde_str_t
2006-01-10 13:57:54 +00:00
{
2006-03-03 11:45:45 +00:00
XP_AWK_NDE_HDR;
2006-03-05 17:07:33 +00:00
xp_char_t* buf;
xp_size_t len;
2006-01-10 13:57:54 +00:00
};
2006-04-24 11:26:00 +00:00
/* XP_AWK_NDE_REX */
struct xp_awk_nde_rex_t
{
XP_AWK_NDE_HDR;
2006-07-01 16:07:06 +00:00
/* TODO: implement the regular expression value node */
2006-04-24 11:26:00 +00:00
xp_char_t* buf;
xp_size_t len;
};
2006-07-01 07:57:10 +00:00
/* XP_AWK_NDE_NAMED, XP_AWK_NDE_GLOBAL,
* XP_AWK_NDE_LOCAL, XP_AWK_NDE_ARG
* XP_AWK_NDE_NAMEDIDX, XP_AWK_NDE_GLOBALIDX,
* XP_AWK_NDE_LOCALIDX, XP_AWK_NDE_ARGIDX */
2006-03-03 11:45:45 +00:00
struct xp_awk_nde_var_t
2006-01-24 16:14:28 +00:00
{
2006-03-03 11:45:45 +00:00
XP_AWK_NDE_HDR;
2006-04-14 10:56:42 +00:00
struct /* could it be union? */
2006-01-24 16:14:28 +00:00
{
xp_char_t* name;
xp_size_t idxa;
} id;
2006-07-01 07:57:10 +00:00
xp_awk_nde_t* idx; /* XP_NULL for non-XXXXIDX */
2006-01-19 16:28:21 +00:00
};
2006-07-14 04:19:22 +00:00
/* XP_AWK_NDE_BFN, XP_AWK_NDE_AFN */
2006-03-03 11:45:45 +00:00
struct xp_awk_nde_call_t
2006-01-19 16:28:21 +00:00
{
2006-03-04 15:54:37 +00:00
XP_AWK_NDE_HDR;
2006-06-19 15:43:27 +00:00
union
{
xp_char_t* name;
2006-07-14 04:19:22 +00:00
/* minimum information of a built-in function
* needed during run-time. */
struct
{
2006-07-14 05:21:30 +00:00
const xp_char_t* name;
2006-07-14 04:19:22 +00:00
xp_size_t min_args;
xp_size_t max_args;
int (*handler) (void* run);
} bfn;
/* xp_awk_bfn_t* bfn; */
2006-06-19 15:43:27 +00:00
} what;
2006-03-03 11:45:45 +00:00
xp_awk_nde_t* args;
2006-04-18 16:04:59 +00:00
xp_size_t nargs;
2006-01-13 11:25:52 +00:00
};
2006-06-12 15:11:02 +00:00
/* XP_AWK_NDE_GETLINE */
struct xp_awk_nde_getline_t
{
XP_AWK_NDE_HDR;
xp_awk_nde_t* var;
2006-06-22 14:15:02 +00:00
int in_type; /* XP_AWK_GETLINE_XXX */
2006-06-13 08:35:53 +00:00
xp_awk_nde_t* in;
};
2006-03-04 15:54:37 +00:00
/* XP_AWK_NDE_IF */
2006-03-03 11:45:45 +00:00
struct xp_awk_nde_if_t
2006-01-09 12:51:47 +00:00
{
2006-03-04 15:54:37 +00:00
XP_AWK_NDE_HDR;
2006-03-03 11:45:45 +00:00
xp_awk_nde_t* test;
xp_awk_nde_t* then_part;
xp_awk_nde_t* else_part; /* optional */
2006-01-09 12:51:47 +00:00
};
2006-03-04 15:54:37 +00:00
/* XP_AWK_NDE_WHILE, XP_AWK_NDE_DOWHILE */
2006-03-03 11:45:45 +00:00
struct xp_awk_nde_while_t
2006-01-10 13:57:54 +00:00
{
2006-03-04 15:54:37 +00:00
XP_AWK_NDE_HDR;
2006-03-03 11:45:45 +00:00
xp_awk_nde_t* test;
xp_awk_nde_t* body;
2006-01-10 13:57:54 +00:00
};
2006-03-04 15:54:37 +00:00
/* XP_AWK_NDE_FOR */
2006-03-03 11:45:45 +00:00
struct xp_awk_nde_for_t
2006-01-19 13:28:29 +00:00
{
2006-03-04 15:54:37 +00:00
XP_AWK_NDE_HDR;
2006-03-03 11:45:45 +00:00
xp_awk_nde_t* init; /* optional */
xp_awk_nde_t* test; /* optional */
xp_awk_nde_t* incr; /* optional */
xp_awk_nde_t* body;
2006-01-19 13:28:29 +00:00
};
2006-04-29 12:09:29 +00:00
/* XP_AWK_NDE_FOREACH */
struct xp_awk_nde_foreach_t
{
XP_AWK_NDE_HDR;
xp_awk_nde_t* test;
xp_awk_nde_t* body;
};
2006-03-04 15:54:37 +00:00
/* XP_AWK_NDE_BREAK */
struct xp_awk_nde_break_t
{
XP_AWK_NDE_HDR;
};
/* XP_AWK_NDE_CONTINUE */
struct xp_awk_nde_continue_t
{
XP_AWK_NDE_HDR;
};
/* XP_AWK_NDE_RETURN */
struct xp_awk_nde_return_t
{
XP_AWK_NDE_HDR;
2006-03-05 17:07:33 +00:00
xp_awk_nde_t* val; /* optional (no return code if XP_NULL) */
2006-03-04 15:54:37 +00:00
};
/* XP_AWK_NDE_EXIT */
struct xp_awk_nde_exit_t
{
XP_AWK_NDE_HDR;
2006-03-05 17:07:33 +00:00
xp_awk_nde_t* val; /* optional (no exit code if XP_NULL) */
2006-03-04 15:54:37 +00:00
};
2006-04-22 16:16:40 +00:00
/* XP_AWK_NDE_NEXT */
struct xp_awk_nde_next_t
{
XP_AWK_NDE_HDR;
};
/* XP_AWK_NDE_NEXTFILE */
struct xp_awk_nde_nextfile_t
{
XP_AWK_NDE_HDR;
};
2006-06-27 14:18:19 +00:00
/* XP_AWK_NDE_DELETE */
struct xp_awk_nde_delete_t
{
XP_AWK_NDE_HDR;
xp_awk_nde_t* var;
};
/* XP_AWK_NDE_PRINT */
struct xp_awk_nde_print_t
{
XP_AWK_NDE_HDR;
xp_awk_nde_t* args;
2006-06-28 03:44:40 +00:00
int out_type; /* XP_AWK_OUT_XXX */
2006-06-27 14:18:19 +00:00
xp_awk_nde_t* out;
};
2006-01-14 14:09:52 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2006-03-03 11:45:45 +00:00
void xp_awk_prnpt (xp_awk_nde_t* tree);
2006-05-07 17:45:08 +00:00
void xp_awk_prnptnpt (xp_awk_nde_t* tree);
2006-03-03 11:45:45 +00:00
void xp_awk_clrpt (xp_awk_nde_t* tree);
2006-01-14 14:09:52 +00:00
#ifdef __cplusplus
}
#endif
2006-01-09 12:51:47 +00:00
#endif