*** empty log message ***

This commit is contained in:
hyung-hwan 2006-06-27 10:53:04 +00:00
parent c7059afc6d
commit 2e70ee9475
6 changed files with 107 additions and 32 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.56 2006-06-22 04:25:44 bacon Exp $
* $Id: awk.c,v 1.57 2006-06-27 10:53:04 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -75,6 +75,8 @@ xp_awk_t* xp_awk_open (void)
awk->tree.chain = XP_NULL;
awk->tree.chain_tail = XP_NULL;
awk->token.prev = 0;
awk->token.type = 0;
awk->token.line = 1;
awk->token.column = 1;

View File

@ -1,5 +1,5 @@
/*
* $Id: awk_i.h,v 1.21 2006-06-21 13:52:15 bacon Exp $
* $Id: awk_i.h,v 1.22 2006-06-27 10:53:04 bacon Exp $
*/
#ifndef _XP_AWK_AWKI_H_
@ -118,6 +118,7 @@ struct xp_awk_t
/* token */
struct
{
int prev;
int type;
xp_str_t name;
xp_size_t line;

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.122 2006-06-25 15:26:57 bacon Exp $
* $Id: parse.c,v 1.123 2006-06-27 10:53:04 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -248,7 +248,11 @@ static struct __kwent __bvtab[] =
c = (awk)->lex.curc; \
} while(0)
#define SET_TOKEN_TYPE(awk,code) ((awk)->token.type = code)
#define SET_TOKEN_TYPE(awk,code) \
do { \
(awk)->token.prev = (awk)->token.type; \
(awk)->token.type = (code); \
} while (0);
#define ADD_TOKEN_CHAR(awk,c) \
do { \
@ -2782,13 +2786,12 @@ static xp_awk_nde_t* __parse_delete (xp_awk_t* awk)
static xp_awk_nde_t* __parse_print (xp_awk_t* awk)
{
xp_awk_nde_print_t* nde;
xp_awk_nde_t* args = XP_NULL;
xp_awk_nde_t* args = XP_NULL;
xp_awk_nde_t* args_tail = XP_NULL;
xp_awk_nde_t* tail_prev = XP_NULL;
xp_awk_nde_t* out = XP_NULL;
int out_type;
/* TODO: handle expression list, not just a single expression */
/* TODO: handle ambiguiouty print "1111" > "2222". is > redirection? */
if (!MATCH(awk,TOKEN_SEMICOLON) &&
!MATCH(awk,TOKEN_GT) &&
!MATCH(awk,TOKEN_RSHIFT) &&
@ -2797,27 +2800,86 @@ static xp_awk_nde_t* __parse_print (xp_awk_t* awk)
{
args = __parse_expression (awk);
if (args == XP_NULL) return XP_NULL;
}
out_type = MATCH(awk,TOKEN_GT)? XP_AWK_PRINT_FILE:
MATCH(awk,TOKEN_RSHIFT)? XP_AWK_PRINT_FILE_APPEND:
MATCH(awk,TOKEN_BOR)? XP_AWK_PRINT_PIPE:
MATCH(awk,TOKEN_BORAND)? XP_AWK_PRINT_COPROC:
XP_AWK_PRINT_CONSOLE;
args_tail = args;
tail_prev = XP_NULL;
if (out_type != XP_AWK_PRINT_CONSOLE)
{
if (__get_token(awk) == -1)
while (MATCH(awk,TOKEN_COMMA))
{
if (args != XP_NULL) xp_awk_clrpt (args);
return XP_NULL;
if (__get_token(awk) == -1)
{
xp_awk_clrpt (args);
return XP_NULL;
}
args_tail->next = __parse_expression (awk);
if (args_tail->next == XP_NULL)
{
xp_awk_clrpt (args);
return XP_NULL;
}
tail_prev = args_tail;
args_tail = args_tail->next;
}
out = __parse_expression(awk);
if (out == XP_NULL)
/* print 1 > 2 would print 1 to the file named 2.
* print (1 > 2) would print (1 > 2) in the console */
if (awk->token.prev != TOKEN_RPAREN &&
args_tail->type == XP_AWK_NDE_EXP_BIN)
{
if (args != XP_NULL) xp_awk_clrpt (args);
return XP_NULL;
xp_awk_nde_exp_t* ep = (xp_awk_nde_exp_t*)args_tail;
if (ep->opcode == XP_AWK_BINOP_GT)
{
xp_awk_nde_t* tmp = args_tail;
if (tail_prev != XP_NULL)
tail_prev->next = ep->left;
else args = ep->left;
out = ep->right;
out_type = XP_AWK_PRINT_FILE;
xp_free (tmp);
}
else if (ep->opcode == XP_AWK_BINOP_RSHIFT)
{
xp_awk_nde_t* tmp = args_tail;
if (tail_prev != XP_NULL)
tail_prev->next = ep->left;
else args = ep->left;
out = ep->right;
out_type = XP_AWK_PRINT_FILE_APPEND;
xp_free (tmp);
}
}
}
if (out == XP_NULL)
{
out_type = MATCH(awk,TOKEN_GT)? XP_AWK_PRINT_FILE:
MATCH(awk,TOKEN_RSHIFT)? XP_AWK_PRINT_FILE_APPEND:
MATCH(awk,TOKEN_BOR)? XP_AWK_PRINT_PIPE:
MATCH(awk,TOKEN_BORAND)? XP_AWK_PRINT_COPROC:
XP_AWK_PRINT_CONSOLE;
if (out_type != XP_AWK_PRINT_CONSOLE)
{
if (__get_token(awk) == -1)
{
if (args != XP_NULL) xp_awk_clrpt (args);
return XP_NULL;
}
out = __parse_expression(awk);
if (out == XP_NULL)
{
if (args != XP_NULL) xp_awk_clrpt (args);
return XP_NULL;
}
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.108 2006-06-26 15:09:28 bacon Exp $
* $Id: run.c,v 1.109 2006-06-27 10:53:04 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -1110,7 +1110,7 @@ static int __run_print_statement (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
if (p->out != XP_NULL)
{
v = __eval_expression (run, p->out);
if (out == XP_NULL) return -1;
if (v == XP_NULL) return -1;
xp_awk_refupval (v);
out = xp_awk_valtostr (v, &errnum, XP_NULL);
@ -1127,7 +1127,8 @@ static int __run_print_statement (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
if (p->args == XP_NULL)
{
/* TODO: get $0 ans use it for v */
v = xp_awk_makestrval0 (XP_T("<TODO: PRINT $0 WITH A TRAILING NEWLINE>\n"));
v = xp_awk_makestrval0 (
XP_T("<TODO: PRINT $0 WITH A TRAILING NEWLINE>\n"));
if (v == XP_NULL)
{
if (out != XP_NULL) xp_free (out);
@ -1168,6 +1169,8 @@ static int __run_print_statement (xp_awk_run_t* run, xp_awk_nde_print_t* nde)
xp_awk_refdownval (run, v);
/* TODO: how to handle n == -1 && errnum == XP_AWK_ENOERR. that is the user handler returned an error... */
/* TODO: print proper field separator */
}
/* TODO: predefine the new line string

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.43 2006-06-26 15:09:28 bacon Exp $
* $Id: awk.c,v 1.44 2006-06-27 10:53:04 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -230,11 +230,8 @@ xp_printf (XP_TEXT("closing %s of type %d\n"), epa->name, epa->type);
case XP_AWK_IO_WRITE:
{
/*
if (_fputts (data, size, (FILE*)epa->handle) == XP_NULL)
return 0;
return size;
*/
/* TODO: how to return error or 0 */
_fputts (data, /*size,*/ (FILE*)epa->handle);
return -1;
}

10
ase/test/awk/t11.awk Normal file
View File

@ -0,0 +1,10 @@
BEGIN
{
print "this is only a test";
print;
print 1, 2, (3 >> 10);
print 1, 2, 3 >> 10;
print 3, 4, 5 >> 10;
close (10);
print "-------------" >> 10;
}