added parser code

This commit is contained in:
hyung-hwan 2011-06-21 08:56:40 +00:00
parent 2008bdeef1
commit faf421a54c
5 changed files with 835 additions and 701 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: str.h 464 2011-05-19 03:33:28Z hyunghwan.chung $ * $Id: str.h 497 2011-06-20 14:56:40Z hyunghwan.chung $
* *
Copyright 2006-2011 Chung, Hyung-Hwan. Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -2168,7 +2168,12 @@ void qse_mbs_fini (
int qse_mbs_yield ( int qse_mbs_yield (
qse_mbs_t* str, /**< string */ qse_mbs_t* str, /**< string */
qse_mxstr_t* buf, /**< buffer pointer */ qse_mxstr_t* buf, /**< buffer pointer */
qse_size_t new_capa /**< new capacity */ qse_size_t newcapa /**< new capacity */
);
qse_mchar_t* qse_mbs_yieldptr (
qse_mbs_t* str, /**< string */
qse_size_t newcapa /**< new capacity */
); );
/** /**
@ -2335,6 +2340,11 @@ int qse_wcs_yield (
qse_size_t new_capa /**< new capacity */ qse_size_t new_capa /**< new capacity */
); );
qse_wchar_t* qse_wcs_yieldptr (
qse_wcs_t* str, /**< string */
qse_size_t newcapa /**< new capacity */
);
/** /**
* The qse_wcs_getsizer() function gets the sizer. * The qse_wcs_getsizer() function gets the sizer.
* @return sizer function set or QSE_NULL if no sizer is set. * @return sizer function set or QSE_NULL if no sizer is set.
@ -2465,6 +2475,7 @@ qse_size_t qse_wcs_pac (
# define qse_str_init(str,mmgr,capa) qse_mbs_init(str,mmgr,capa) # define qse_str_init(str,mmgr,capa) qse_mbs_init(str,mmgr,capa)
# define qse_str_fini(str) qse_mbs_fini(str) # define qse_str_fini(str) qse_mbs_fini(str)
# define qse_str_yield(str,buf,ncapa) qse_mbs_yield(str,buf,ncapa) # define qse_str_yield(str,buf,ncapa) qse_mbs_yield(str,buf,ncapa)
# define qse_str_yieldptr(str,ncapa) qse_mbs_yieldptr(str,ncapa)
# define qse_str_getsizer(str) qse_mbs_getsizer(str) # define qse_str_getsizer(str) qse_mbs_getsizer(str)
# define qse_str_setsizer(str,sizer) qse_mbs_setsizer(str,sizer) # define qse_str_setsizer(str,sizer) qse_mbs_setsizer(str,sizer)
# define qse_str_getcapa(str) qse_mbs_getcapa(str) # define qse_str_getcapa(str) qse_mbs_getcapa(str)
@ -2490,6 +2501,7 @@ qse_size_t qse_wcs_pac (
# define qse_str_init(str,mmgr,capa) qse_wcs_init(str,mmgr,capa) # define qse_str_init(str,mmgr,capa) qse_wcs_init(str,mmgr,capa)
# define qse_str_fini(str) qse_wcs_fini(str) # define qse_str_fini(str) qse_wcs_fini(str)
# define qse_str_yield(str,buf,ncapa) qse_wcs_yield(str,buf,ncapa) # define qse_str_yield(str,buf,ncapa) qse_wcs_yield(str,buf,ncapa)
# define qse_str_yieldptr(str,ncapa) qse_wcs_yieldptr(str,ncapa)
# define qse_str_getsizer(str) qse_wcs_getsizer(str) # define qse_str_getsizer(str) qse_wcs_getsizer(str)
# define qse_str_setsizer(str,sizer) qse_wcs_setsizer(str,sizer) # define qse_str_setsizer(str,sizer) qse_wcs_setsizer(str,sizer)
# define qse_str_getcapa(str) qse_wcs_getcapa(str) # define qse_str_getcapa(str) qse_wcs_getcapa(str)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: str_dynm.c 462 2011-05-18 14:36:40Z hyunghwan.chung $ * $Id: str_dynm.c 497 2011-06-20 14:56:40Z hyunghwan.chung $
* *
Copyright 2006-2011 Chung, Hyung-Hwan. Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -84,15 +84,15 @@ void qse_mbs_fini (qse_mbs_t* str)
if (str->val.ptr != QSE_NULL) QSE_MMGR_FREE (str->mmgr, str->val.ptr); if (str->val.ptr != QSE_NULL) QSE_MMGR_FREE (str->mmgr, str->val.ptr);
} }
int qse_mbs_yield (qse_mbs_t* str, qse_mxstr_t* buf, qse_size_t new_capa) int qse_mbs_yield (qse_mbs_t* str, qse_mxstr_t* buf, qse_size_t newcapa)
{ {
qse_mchar_t* tmp; qse_mchar_t* tmp;
if (new_capa == 0) tmp = QSE_NULL; if (newcapa == 0) tmp = QSE_NULL;
else else
{ {
tmp = (qse_mchar_t*) QSE_MMGR_ALLOC ( tmp = (qse_mchar_t*) QSE_MMGR_ALLOC (
str->mmgr, QSE_SIZEOF(qse_mchar_t) * (new_capa + 1)); str->mmgr, QSE_SIZEOF(qse_mchar_t) * (newcapa + 1));
if (tmp == QSE_NULL) return -1; if (tmp == QSE_NULL) return -1;
tmp[0] = QSE_MT('\0'); tmp[0] = QSE_MT('\0');
} }
@ -105,11 +105,18 @@ int qse_mbs_yield (qse_mbs_t* str, qse_mxstr_t* buf, qse_size_t new_capa)
str->val.ptr = tmp; str->val.ptr = tmp;
str->val.len = 0; str->val.len = 0;
str->capa = new_capa; str->capa = newcapa;
return 0; return 0;
} }
qse_mchar_t* qse_mbs_yieldptr (qse_mbs_t* str, qse_size_t newcapa)
{
qse_mxstr_t mx;
if (qse_mbs_yield (str, &mx, newcapa) <= -1) return QSE_NULL;
return mx.ptr;
}
qse_mbs_sizer_t qse_mbs_getsizer (qse_mbs_t* str) qse_mbs_sizer_t qse_mbs_getsizer (qse_mbs_t* str)
{ {
return str->sizer; return str->sizer;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: str_dynw.c 462 2011-05-18 14:36:40Z hyunghwan.chung $ * $Id: str_dynw.c 497 2011-06-20 14:56:40Z hyunghwan.chung $
* *
Copyright 2006-2011 Chung, Hyung-Hwan. Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -84,15 +84,15 @@ void qse_wcs_fini (qse_wcs_t* str)
if (str->val.ptr != QSE_NULL) QSE_MMGR_FREE (str->mmgr, str->val.ptr); if (str->val.ptr != QSE_NULL) QSE_MMGR_FREE (str->mmgr, str->val.ptr);
} }
int qse_wcs_yield (qse_wcs_t* str, qse_wxstr_t* buf, qse_size_t new_capa) int qse_wcs_yield (qse_wcs_t* str, qse_wxstr_t* buf, qse_size_t newcapa)
{ {
qse_wchar_t* tmp; qse_wchar_t* tmp;
if (new_capa == 0) tmp = QSE_NULL; if (newcapa == 0) tmp = QSE_NULL;
else else
{ {
tmp = (qse_wchar_t*) QSE_MMGR_ALLOC ( tmp = (qse_wchar_t*) QSE_MMGR_ALLOC (
str->mmgr, QSE_SIZEOF(qse_wchar_t) * (new_capa + 1)); str->mmgr, QSE_SIZEOF(qse_wchar_t) * (newcapa + 1));
if (tmp == QSE_NULL) return -1; if (tmp == QSE_NULL) return -1;
tmp[0] = QSE_WT('\0'); tmp[0] = QSE_WT('\0');
} }
@ -105,11 +105,18 @@ int qse_wcs_yield (qse_wcs_t* str, qse_wxstr_t* buf, qse_size_t new_capa)
str->val.ptr = tmp; str->val.ptr = tmp;
str->val.len = 0; str->val.len = 0;
str->capa = new_capa; str->capa = newcapa;
return 0; return 0;
} }
qse_wchar_t* qse_wcs_yieldptr (qse_wcs_t* str, qse_size_t newcapa)
{
qse_wxstr_t wx;
if (qse_wcs_yield (str, &wx, newcapa) <= -1) return QSE_NULL;
return wx.ptr;
}
qse_wcs_sizer_t qse_wcs_getsizer (qse_wcs_t* str) qse_wcs_sizer_t qse_wcs_getsizer (qse_wcs_t* str)
{ {
return str->sizer; return str->sizer;

File diff suppressed because it is too large Load Diff

View File

@ -1,73 +1,75 @@
/* /*
* $Id: parser.h 118 2008-03-03 11:21:33Z baconevi $ * $Id: stc.h 118 2008-03-03 11:21:33Z baconevi $
*/ */
#ifndef _QSE_STX_PARSER_H_ #ifndef _QSE_LIB_STX_PAR_H_
#define _QSE_STX_PARSER_H_ #define _QSE_LIB_STX_PAR_H_
#include <qse/stx/stx.h> #include "stx.h"
#include <qse/stx/name.h>
#include <qse/stx/token.h> #include <qse/cmn/str.h>
#include <qse/bas/arr.h> #include <qse/cmn/lda.h>
enum enum
{ {
QSE_STX_PARSER_ERROR_NONE, QSE_STC_ERROR_NONE,
/* system errors */ /* system errors */
QSE_STX_PARSER_ERROR_INPUT_FUNC, QSE_STC_ERROR_INPUT_FUNC,
QSE_STX_PARSER_ERROR_INPUT, QSE_STC_ERROR_INPUT,
QSE_STX_PARSER_ERROR_MEMORY, QSE_STC_ERROR_MEMORY,
/* lexical errors */ /* lexical errors */
QSE_STX_PARSER_ERROR_CHAR, QSE_STC_ERROR_CHAR,
QSE_STX_PARSER_ERROR_CHARLIT, QSE_STC_ERROR_CHARLIT,
QSE_STX_PARSER_ERROR_STRLIT, QSE_STC_ERROR_STRLIT,
QSE_STX_PARSER_ERROR_LITERAL, QSE_STC_ERROR_LITERAL,
/* syntatic error */ /* syntatic error */
QSE_STX_PARSER_ERROR_MESSAGE_SELECTOR, QSE_STC_ERROR_MESSAGE_SELECTOR,
QSE_STX_PARSER_ERROR_ARGUMENT_NAME, QSE_STC_ERROR_ARGUMENT_NAME,
QSE_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS, QSE_STC_ERROR_TOO_MANY_ARGUMENTS,
QSE_STX_PARSER_ERROR_PRIMITIVE_KEYWORD, QSE_STC_ERROR_PRIMITIVE_KEYWORD,
QSE_STX_PARSER_ERROR_PRIMITIVE_NUMBER, QSE_STC_ERROR_PRIMITIVE_NUMBER,
QSE_STX_PARSER_ERROR_PRIMITIVE_NUMBER_RANGE, QSE_STC_ERROR_PRIMITIVE_NUMBER_RANGE,
QSE_STX_PARSER_ERROR_PRIMITIVE_NOT_CLOSED, QSE_STC_ERROR_PRIMITIVE_NOT_CLOSED,
QSE_STX_PARSER_ERROR_TEMPORARIES_NOT_CLOSED, QSE_STC_ERROR_TEMPORARIES_NOT_CLOSED,
QSE_STX_PARSER_ERROR_TOO_MANY_TEMPORARIES, QSE_STC_ERROR_TOO_MANY_TEMPORARIES,
QSE_STX_PARSER_ERROR_PSEUDO_VARIABLE, QSE_STC_ERROR_PSEUDO_VARIABLE,
QSE_STX_PARSER_ERROR_PRIMARY, QSE_STC_ERROR_PRIMARY,
QSE_STX_PARSER_ERROR_NO_PERIOD, QSE_STC_ERROR_NO_PERIOD,
QSE_STX_PARSER_ERROR_NO_RPAREN, QSE_STC_ERROR_NO_RPAREN,
QSE_STX_PARSER_ERROR_BLOCK_ARGUMENT_NAME, QSE_STC_ERROR_BLOCK_ARGUMENT_NAME,
QSE_STX_PARSER_ERROR_BLOCK_ARGUMENT_LIST, QSE_STC_ERROR_BLOCK_ARGUMENT_LIST,
QSE_STX_PARSER_ERROR_BLOCK_NOT_CLOSED, QSE_STC_ERROR_BLOCK_NOT_CLOSED,
QSE_STX_PARSER_ERROR_UNDECLARED_NAME, QSE_STC_ERROR_UNDECLARED_NAME,
QSE_STX_PARSER_ERROR_TOO_MANY_LITERALS QSE_STC_ERROR_TOO_MANY_LITERALS
}; };
enum enum
{ {
/* input_func cmd */ /* input_func cmd */
QSE_STX_PARSER_INPUT_OPEN, QSE_STC_INPUT_OPEN,
QSE_STX_PARSER_INPUT_CLOSE, QSE_STC_INPUT_CLOSE,
QSE_STX_PARSER_INPUT_CONSUME, QSE_STC_INPUT_CONSUME,
QSE_STX_PARSER_INPUT_REWIND QSE_STC_INPUT_REWIND
}; };
typedef struct qse_stx_parser_t qse_stx_parser_t; typedef struct qse_stc_t qse_stc_t;
struct qse_stx_parser_t struct qse_stc_t
{ {
qse_mmgr_t* mmgr;
qse_stx_t* stx; qse_stx_t* stx;
int error_code; int error_code;
qse_word_t method_class; qse_word_t method_class;
qse_stx_name_t method_name; qse_str_t method_name;
qse_char_t* temporaries[256]; /* TODO: different size? or dynamic? */ qse_char_t* temporaries[256]; /* TODO: different size? or dynamic? */
qse_word_t argument_count; qse_word_t argument_count;
@ -76,29 +78,56 @@ struct qse_stx_parser_t
qse_word_t literals[256]; /* TODO: make it a dynamic array */ qse_word_t literals[256]; /* TODO: make it a dynamic array */
qse_word_t literal_count; qse_word_t literal_count;
qse_arr_t bytecode; qse_lda_t bytecode;
struct
{
int type;
/*
qse_stx_int_t ivalue;
qse_stx_real_t fvalue;
*/
qse_str_t name;
} token;
qse_stx_token_t token;
qse_cint_t curc; qse_cint_t curc;
qse_cint_t ungotc[5]; qse_cint_t ungotc[5];
qse_size_t ungotc_count; qse_size_t ungotc_count;
void* input_owner; void* input_owner;
int (*input_func) (int cmd, void* owner, void* arg); int (*input_func) (int cmd, void* owner, void* arg);
qse_bool_t __dynamic;
}; };
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
qse_stx_parser_t* qse_stx_parser_open (qse_stx_parser_t* parser, qse_stx_t* stx); qse_stc_t* qse_stc_open (
void qse_stx_parser_close (qse_stx_parser_t* parser); qse_mmgr_t* mmgr,
qse_size_t xtnsize,
qse_stx_t* stx
);
const qse_char_t* qse_stx_parser_error_string (qse_stx_parser_t* parser); void qse_stc_close (
int qse_stx_parser_parse_method ( qse_stc_t* stc
qse_stx_parser_t* parser, qse_word_t method_class, void* input); );
qse_stc_t* qse_stc_init (
qse_stc_t* stc,
qse_mmgr_t* mmgr,
qse_stx_t* stx
);
void qse_stc_fini (
qse_stc_t* stc
);
int qse_stc_parsemethod (
qse_stc_t* stc,
qse_word_t method_class,
void* input
);
#ifdef __cplusplus #ifdef __cplusplus
} }