added partial code to support 'include'

This commit is contained in:
hyung-hwan 2009-07-20 07:02:33 +00:00
parent 35e65743ab
commit 4bb3fe77eb
4 changed files with 43 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.hpp 239 2009-07-18 12:02:24Z hyunghwan.chung $ * $Id: Awk.hpp 240 2009-07-19 13:02:33Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -145,6 +145,7 @@ public:
ERR_PRINTFARG = QSE_AWK_EPRINTFARG, ERR_PRINTFARG = QSE_AWK_EPRINTFARG,
ERR_PREPST = QSE_AWK_EPREPST, ERR_PREPST = QSE_AWK_EPREPST,
ERR_INCDECOPR = QSE_AWK_EINCDECOPR, ERR_INCDECOPR = QSE_AWK_EINCDECOPR,
ERR_INCLSTR = QSE_AWK_EINCLSTR,
ERR_DIVBY0 = QSE_AWK_EDIVBY0, ERR_DIVBY0 = QSE_AWK_EDIVBY0,
ERR_OPERAND = QSE_AWK_EOPERAND, ERR_OPERAND = QSE_AWK_EOPERAND,
ERR_POSIDX = QSE_AWK_EPOSIDX, ERR_POSIDX = QSE_AWK_EPOSIDX,

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h 239 2009-07-18 12:02:24Z hyunghwan.chung $ * $Id: awk.h 240 2009-07-19 13:02:33Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -681,6 +681,7 @@ enum qse_awk_errnum_t
QSE_AWK_EPRINTFARG,/**< 'printf' not followed by argument */ QSE_AWK_EPRINTFARG,/**< 'printf' not followed by argument */
QSE_AWK_EPREPST, /**< both prefix and postfix incr/decr operator present */ QSE_AWK_EPREPST, /**< both prefix and postfix incr/decr operator present */
QSE_AWK_EINCDECOPR,/**< illegal operand for incr/decr operator */ QSE_AWK_EINCDECOPR,/**< illegal operand for incr/decr operator */
QSE_AWK_EINCLSTR, /**< 'include' not followed by a string */
/* run time error */ /* run time error */
QSE_AWK_EDIVBY0, /**< divide by zero */ QSE_AWK_EDIVBY0, /**< divide by zero */

View File

@ -1,5 +1,5 @@
/* /*
* $Id: err.c 235 2009-07-15 10:43:31Z hyunghwan.chung $ * $Id: err.c 240 2009-07-19 13:02:33Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -108,6 +108,7 @@ const qse_char_t* qse_awk_dflerrstr (qse_awk_t* awk, qse_awk_errnum_t errnum)
QSE_T("'printf' not followed by argument"), QSE_T("'printf' not followed by argument"),
QSE_T("both prefix and postfix increment/decrement operator present"), QSE_T("both prefix and postfix increment/decrement operator present"),
QSE_T("illegal operand for increment/decrement operator"), QSE_T("illegal operand for increment/decrement operator"),
QSE_T("'include' not followed by a string"),
QSE_T("divide by zero"), QSE_T("divide by zero"),
QSE_T("invalid operand"), QSE_T("invalid operand"),

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c 239 2009-07-18 12:02:24Z hyunghwan.chung $ * $Id: parse.c 240 2009-07-19 13:02:33Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -592,10 +592,31 @@ exit_parse:
return n; return n;
} }
static int begin_include (qse_awk_t* awk)
{
if (qse_strlen(awk->token.name->ptr) != awk->token.name->len)
{
qse_cstr_t errarg;
SETERRARG (
awk,
QSE_AWK_EIONMNL,
awk->token.line,
awk->token.name->ptr,
qse_strlen(awk->token.name->ptr)
);
return -1;
}
/* TODO: implement this */
SETERRLIN (awk, QSE_AWK_ENOSUP, awk->ptoken.line);
return -1;
}
static qse_awk_t* parse_progunit (qse_awk_t* awk) static qse_awk_t* parse_progunit (qse_awk_t* awk)
{ {
/* /*
global xxx, xxxx; global xxx, xxxx;
include "xxxx";
BEGIN { action } BEGIN { action }
END { action } END { action }
pattern { action } pattern { action }
@ -604,6 +625,7 @@ static qse_awk_t* parse_progunit (qse_awk_t* awk)
QSE_ASSERT (awk->parse.depth.cur.loop == 0); QSE_ASSERT (awk->parse.depth.cur.loop == 0);
retry:
if ((awk->option & QSE_AWK_EXPLICIT) && MATCH(awk,TOKEN_GLOBAL)) if ((awk->option & QSE_AWK_EXPLICIT) && MATCH(awk,TOKEN_GLOBAL))
{ {
qse_size_t ngbls; qse_size_t ngbls;
@ -623,6 +645,19 @@ static qse_awk_t* parse_progunit (qse_awk_t* awk)
return QSE_NULL; return QSE_NULL;
} }
} }
else if (MATCH(awk,TOKEN_INCLUDE))
{
if (get_token(awk) <= -1) return QSE_NULL;
if (!MATCH(awk,TOKEN_STR))
{
SETERRLIN (awk, QSE_AWK_EINCLSTR, awk->ptoken.line);
return QSE_NULL;
}
if (begin_include (awk) <= -1) return QSE_NULL;
goto retry;
}
else if (MATCH(awk,TOKEN_FUNCTION)) else if (MATCH(awk,TOKEN_FUNCTION))
{ {
awk->parse.id.block = PARSE_FUNCTION; awk->parse.id.block = PARSE_FUNCTION;
@ -1943,13 +1978,7 @@ static qse_awk_nde_t* parse_statement_nb (qse_awk_t* awk, qse_size_t line)
} }
/* keywords that require a terminating semicolon */ /* keywords that require a terminating semicolon */
if (MATCH(awk,TOKEN_INCLUDE)) if (MATCH(awk,TOKEN_DO))
{
/* TODO: implement include */
SETERRLIN (awk, QSE_AWK_ENOSUP, line);
return QSE_NULL;
}
else if (MATCH(awk,TOKEN_DO))
{ {
if (get_token(awk) <= -1) return QSE_NULL; if (get_token(awk) <= -1) return QSE_NULL;