*** empty log message ***

This commit is contained in:
hyung-hwan 2006-01-28 06:38:01 +00:00
parent 111b108ec0
commit e701a98406
3 changed files with 87 additions and 23 deletions

View File

@ -1,3 +1,35 @@
Programs
pattern { action }
function name (parameter-list) { statement }
Patterns
BEGIN
END
expresion
/regular expression/
pattern && pattern
pattern || pattern
!pattern
(pattern)
pattern, pattern -> range pattern
Actions
break
continue
delete array-element
do statement while (expression)
exit [expression]
expression
if (expression) statement [else statement]
input-output statement
for (expression; expression; expression) statement
for (variable in array) statement
next
return [expression]
while (expression) statement
{ statements }
Variables
global variables (enabled when awk->opt & XP_AWK_OPT_VARDCL)

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.35 2006-01-26 08:06:15 bacon Exp $
* $Id: parse.c,v 1.36 2006-01-28 06:38:01 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -109,6 +109,7 @@ static int __skip_spaces (xp_awk_t* awk);
static int __skip_comment (xp_awk_t* awk);
static int __classfy_ident (const xp_char_t* ident);
static xp_size_t __find_variable (xp_awk_t* awk, const xp_char_t* name);
static xp_size_t __find_func_arg (xp_awk_t* awk, const xp_char_t* name);
static xp_long_t __str_to_long (const xp_char_t* name);
@ -1350,10 +1351,17 @@ static xp_awk_node_t* __parse_return (xp_awk_t* awk)
node->type = XP_AWK_NODE_RETURN;
node->next = XP_NULL;
val = __parse_expression (awk);
if (val == XP_NULL) {
xp_free (node);
return XP_NULL;
if (MATCH(awk,TOKEN_SEMICOLON)) {
/* no return value */
val = XP_NULL;
}
else {
val = __parse_expression (awk);
if (val == XP_NULL) {
xp_free (node);
return XP_NULL;
}
}
node->value = val;
@ -1370,10 +1378,16 @@ static xp_awk_node_t* __parse_exit (xp_awk_t* awk)
node->type = XP_AWK_NODE_EXIT;
node->next = XP_NULL;
val = __parse_expression (awk);
if (val == XP_NULL) {
xp_free (node);
return XP_NULL;
if (MATCH(awk,TOKEN_SEMICOLON)) {
/* no exit code */
val = XP_NULL;
}
else {
val = __parse_expression (awk);
if (val == XP_NULL) {
xp_free (node);
return XP_NULL;
}
}
node->value = val;
@ -1668,6 +1682,11 @@ static int __classfy_ident (const xp_char_t* ident)
return TOKEN_IDENT;
}
static xp_size_t __find_variable (xp_awk_t* awk, const xp_char_t* name)
{
return (xp_size_t)-1;
}
static xp_size_t __find_func_arg (xp_awk_t* awk, const xp_char_t* name)
{
/*

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.c,v 1.12 2006-01-25 16:11:43 bacon Exp $
* $Id: tree.c,v 1.13 2006-01-28 06:38:01 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -211,27 +211,38 @@ static void __print_statements (xp_awk_node_t* tree, int depth)
case XP_AWK_NODE_RETURN:
__print_tabs (depth);
xp_printf (XP_TEXT("return "));
xp_assert (((xp_awk_node_sgv_t*)p)->value->next == XP_NULL);
if (__print_expr_node(((xp_awk_node_sgv_t*)p)->value) == 0) {
xp_printf (XP_TEXT(";\n"));
if (((xp_awk_node_sgv_t*)p)->value == XP_NULL) {
xp_printf (XP_TEXT("return;\n"));
}
else {
xp_awk_node_sgv_t* x = (xp_awk_node_sgv_t*)p;
xp_printf (XP_TEXT("***INTERNAL ERROR: unknown node type - %d\n"), x->type);
xp_printf (XP_TEXT("return "));
xp_assert (((xp_awk_node_sgv_t*)p)->value->next == XP_NULL);
if (__print_expr_node(((xp_awk_node_sgv_t*)p)->value) == 0) {
xp_printf (XP_TEXT(";\n"));
}
else {
xp_awk_node_sgv_t* x = (xp_awk_node_sgv_t*)p;
xp_printf (XP_TEXT("***INTERNAL ERROR: unknown node type - %d\n"), x->type);
}
}
break;
case XP_AWK_NODE_EXIT:
__print_tabs (depth);
xp_printf (XP_TEXT("exit "));
xp_assert (((xp_awk_node_sgv_t*)p)->value->next == XP_NULL);
if (__print_expr_node(((xp_awk_node_sgv_t*)p)->value) == 0) {
xp_printf (XP_TEXT(";\n"));
if (((xp_awk_node_sgv_t*)p)->value == XP_NULL) {
xp_printf (XP_TEXT("exit;\n"));
}
else {
xp_awk_node_sgv_t* x = (xp_awk_node_sgv_t*)p;
xp_printf (XP_TEXT("***INTERNAL ERROR: unknown node type - %d\n"), x->type);
xp_printf (XP_TEXT("exit "));
xp_assert (((xp_awk_node_sgv_t*)p)->value->next == XP_NULL);
if (__print_expr_node(((xp_awk_node_sgv_t*)p)->value) == 0) {
xp_printf (XP_TEXT(";\n"));
}
else {
xp_awk_node_sgv_t* x = (xp_awk_node_sgv_t*)p;
xp_printf (XP_TEXT("***INTERNAL ERROR: unknown node type - %d\n"), x->type);
}
}
break;
@ -318,7 +329,8 @@ void xp_awk_clrpt (xp_awk_node_t* tree)
case XP_AWK_NODE_RETURN:
case XP_AWK_NODE_EXIT:
xp_awk_clrpt (((xp_awk_node_sgv_t*)p)->value);
if (((xp_awk_node_sgv_t*)p)->value != XP_NULL)
xp_awk_clrpt (((xp_awk_node_sgv_t*)p)->value);
xp_free (p);
break;
@ -360,6 +372,7 @@ void xp_awk_clrpt (xp_awk_node_t* tree)
break;
case XP_AWK_NODE_POS:
xp_assert (((xp_awk_node_sgv_t*)p)->value != XP_NULL);
xp_awk_clrpt (((xp_awk_node_sgv_t*)p)->value);
xp_free (p);
break;