*** empty log message ***
This commit is contained in:
		@ -1,5 +1,5 @@
 | 
			
		||||
/*
 | 
			
		||||
 * $Id: awk.c,v 1.19 2006-02-05 16:00:33 bacon Exp $
 | 
			
		||||
 * $Id: awk.c,v 1.20 2006-02-07 15:28:05 bacon Exp $
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <xp/awk/awk.h>
 | 
			
		||||
@ -72,7 +72,8 @@ xp_awk_t* xp_awk_open (xp_awk_t* awk)
 | 
			
		||||
	awk->tree.nglobals = 0;
 | 
			
		||||
	awk->tree.begin = XP_NULL;
 | 
			
		||||
	awk->tree.end = XP_NULL;
 | 
			
		||||
	awk->tree.unnamed = XP_NULL;
 | 
			
		||||
	awk->tree.chain = XP_NULL;
 | 
			
		||||
	awk->tree.chain_tail = XP_NULL;
 | 
			
		||||
 | 
			
		||||
	awk->lex.curc = XP_CHAR_EOF;
 | 
			
		||||
	awk->lex.ungotc_count = 0;
 | 
			
		||||
@ -169,13 +170,19 @@ void xp_awk_clear (xp_awk_t* awk)
 | 
			
		||||
		awk->tree.end = XP_NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	while (awk->tree.unnamed != XP_NULL) {
 | 
			
		||||
		xp_awk_node_t* next = awk->tree.unnamed->next;
 | 
			
		||||
		xp_awk_clrpt (awk->tree.unnamed);
 | 
			
		||||
		awk->tree.unnamed = next;
 | 
			
		||||
	}
 | 
			
		||||
	while (awk->tree.chain != XP_NULL) {
 | 
			
		||||
		xp_awk_chain_t* next = awk->tree.chain->next;
 | 
			
		||||
 | 
			
		||||
		if (awk->tree.chain->pattern != XP_NULL)
 | 
			
		||||
			xp_awk_clrpt (awk->tree.chain->pattern);
 | 
			
		||||
		if (awk->tree.chain->action != XP_NULL)
 | 
			
		||||
			xp_awk_clrpt (awk->tree.chain->action);
 | 
			
		||||
		xp_free (awk->tree.chain);
 | 
			
		||||
 | 
			
		||||
		awk->tree.chain = next;
 | 
			
		||||
	}
 | 
			
		||||
	awk->tree.chain_tail = XP_NULL;
 | 
			
		||||
 | 
			
		||||
	/* TODO: destroy pattern-actions pairs */
 | 
			
		||||
	/* TODO: destroy function list */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
/* 
 | 
			
		||||
 * $Id: awk.h,v 1.26 2006-02-05 16:00:33 bacon Exp $
 | 
			
		||||
 * $Id: awk.h,v 1.27 2006-02-07 15:28:05 bacon Exp $
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef _XP_AWK_AWK_H_
 | 
			
		||||
@ -54,6 +54,7 @@ enum
 | 
			
		||||
 * TYPE: xp_awk_t
 | 
			
		||||
 */
 | 
			
		||||
typedef struct xp_awk_t xp_awk_t;
 | 
			
		||||
typedef struct xp_awk_chain_t xp_awk_chain_t;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * TYPE: xp_awk_io_t
 | 
			
		||||
@ -103,7 +104,8 @@ struct xp_awk_t
 | 
			
		||||
		xp_awk_hash_t funcs;
 | 
			
		||||
		xp_awk_node_t* begin;
 | 
			
		||||
		xp_awk_node_t* end;
 | 
			
		||||
		xp_awk_node_t* unnamed;
 | 
			
		||||
		xp_awk_chain_t* chain;
 | 
			
		||||
		xp_awk_chain_t* chain_tail;
 | 
			
		||||
	} tree;
 | 
			
		||||
 | 
			
		||||
	/* temporary information that the parser needs */
 | 
			
		||||
@ -135,6 +137,13 @@ struct xp_awk_t
 | 
			
		||||
	xp_bool_t __dynamic;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct xp_awk_chain_t
 | 
			
		||||
{
 | 
			
		||||
	xp_awk_node_t* pattern;
 | 
			
		||||
	xp_awk_node_t* action;
 | 
			
		||||
	xp_awk_chain_t* next;	
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
/*
 | 
			
		||||
 * $Id: parse.c,v 1.50 2006-02-05 16:12:50 bacon Exp $
 | 
			
		||||
 * $Id: parse.c,v 1.51 2006-02-07 15:28:05 bacon Exp $
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <xp/awk/awk.h>
 | 
			
		||||
@ -89,6 +89,8 @@ static xp_awk_t*      __collect_locals (xp_awk_t* awk, xp_size_t nlocals);
 | 
			
		||||
static xp_awk_node_t* __parse_function (xp_awk_t* awk);
 | 
			
		||||
static xp_awk_node_t* __parse_begin (xp_awk_t* awk);
 | 
			
		||||
static xp_awk_node_t* __parse_end (xp_awk_t* awk);
 | 
			
		||||
static xp_awk_node_t* __parse_patternless (xp_awk_t* awk);
 | 
			
		||||
 | 
			
		||||
static xp_awk_node_t* __parse_action (xp_awk_t* awk);
 | 
			
		||||
static xp_awk_node_t* __parse_block (xp_awk_t* awk, xp_bool_t is_top);
 | 
			
		||||
static xp_awk_node_t* __parse_statement (xp_awk_t* awk);
 | 
			
		||||
@ -208,6 +210,8 @@ static int __dump_func (xp_awk_pair_t* pair)
 | 
			
		||||
 | 
			
		||||
static void __dump (xp_awk_t* awk)
 | 
			
		||||
{
 | 
			
		||||
	xp_awk_chain_t* chain;
 | 
			
		||||
 | 
			
		||||
	if (awk->tree.nglobals > 0) {
 | 
			
		||||
		xp_size_t i;
 | 
			
		||||
 | 
			
		||||
@ -220,18 +224,24 @@ static void __dump (xp_awk_t* awk)
 | 
			
		||||
 | 
			
		||||
	xp_awk_hash_walk (&awk->tree.funcs, __dump_func);
 | 
			
		||||
 | 
			
		||||
	if (awk->tree.begin != NULL) {
 | 
			
		||||
	if (awk->tree.begin != XP_NULL) {
 | 
			
		||||
		xp_printf (XP_TEXT("BEGIN "));
 | 
			
		||||
		xp_awk_prnpt (awk->tree.begin);
 | 
			
		||||
		xp_printf (XP_TEXT("\n"));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (awk->tree.end != NULL) {
 | 
			
		||||
	chain = awk->tree.chain;
 | 
			
		||||
	while (chain != XP_NULL) {
 | 
			
		||||
		if (chain->pattern != XP_NULL) xp_awk_prnpt (chain->pattern);
 | 
			
		||||
		if (chain->action != XP_NULL) xp_awk_prnpt (chain->action);	
 | 
			
		||||
		xp_printf (XP_TEXT("\n"));
 | 
			
		||||
		chain = chain->next;	
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (awk->tree.end != XP_NULL) {
 | 
			
		||||
		xp_printf (XP_TEXT("END "));
 | 
			
		||||
		xp_awk_prnpt (awk->tree.end);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
// TODO: dump unmaed top-level blocks...
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int xp_awk_parse (xp_awk_t* awk)
 | 
			
		||||
@ -252,9 +262,8 @@ int xp_awk_parse (xp_awk_t* awk)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	awk->tree.nglobals = xp_awk_tab_getsize (&awk->parse.globals);
 | 
			
		||||
	awk->tree.nglobals = xp_awk_tab_getsize(&awk->parse.globals);
 | 
			
		||||
xp_printf (XP_TEXT("-----------------------------\n"));
 | 
			
		||||
xp_printf (XP_TEXT("sucessful end - %d\n"), awk->errnum);
 | 
			
		||||
__dump (awk);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
@ -300,13 +309,7 @@ static xp_awk_t* __parse_progunit (xp_awk_t* awk)
 | 
			
		||||
	pattern, pattern
 | 
			
		||||
	*/
 | 
			
		||||
	else {
 | 
			
		||||
		/* pattern-less actions */
 | 
			
		||||
		xp_awk_node_t* node;
 | 
			
		||||
 | 
			
		||||
		node = __parse_action (awk);
 | 
			
		||||
		if (node == XP_NULL) return XP_NULL;
 | 
			
		||||
 | 
			
		||||
		// TODO: weave the action block into awk->tree.actions...
 | 
			
		||||
		if (__parse_patternless(awk) == XP_NULL) return XP_NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return awk;
 | 
			
		||||
@ -521,6 +524,36 @@ static xp_awk_node_t* __parse_end (xp_awk_t* awk)
 | 
			
		||||
	return node;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static xp_awk_node_t* __parse_patternless (xp_awk_t* awk)
 | 
			
		||||
{
 | 
			
		||||
	xp_awk_node_t* node;
 | 
			
		||||
	xp_awk_chain_t* chain;
 | 
			
		||||
 | 
			
		||||
	node = __parse_action (awk);
 | 
			
		||||
	if (node == XP_NULL) return XP_NULL;
 | 
			
		||||
 | 
			
		||||
	chain = (xp_awk_chain_t*) xp_malloc (xp_sizeof(xp_awk_chain_t));
 | 
			
		||||
	if (chain == XP_NULL) {
 | 
			
		||||
		xp_awk_clrpt (node);
 | 
			
		||||
		PANIC (awk, XP_AWK_ENOMEM);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	chain->pattern = XP_NULL;
 | 
			
		||||
	chain->action = node;
 | 
			
		||||
	chain->next = XP_NULL;
 | 
			
		||||
 | 
			
		||||
	if (awk->tree.chain == XP_NULL) {
 | 
			
		||||
		awk->tree.chain = chain;
 | 
			
		||||
		awk->tree.chain_tail = chain;
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
		awk->tree.chain_tail->next = chain;
 | 
			
		||||
		awk->tree.chain_tail = chain;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return node;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static xp_awk_node_t* __parse_action (xp_awk_t* awk)
 | 
			
		||||
{
 | 
			
		||||
	if (!MATCH(awk,TOKEN_LBRACE)) PANIC (awk, XP_AWK_ELBRACE);
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user