*** empty log message ***

This commit is contained in:
hyung-hwan 2005-06-12 14:40:35 +00:00
parent 159f8979f2
commit 036e2afef0
4 changed files with 76 additions and 29 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: parser.c,v 1.26 2005-06-12 12:33:31 bacon Exp $
* $Id: parser.c,v 1.27 2005-06-12 14:40:35 bacon Exp $
*/
#include <xp/stx/parser.h>
@ -44,8 +44,10 @@ xp_stx_parser_t* xp_stx_parser_open (xp_stx_parser_t* parser, xp_stx_t* stx)
}
parser->stx = stx;
parser->error_code = XP_STX_PARSER_ERROR_NONE;
parser->argument_count = 0;
parser->curc = XP_CHAR_EOF;
parser->ungotc_count = 0;
@ -91,6 +93,7 @@ const xp_char_t* xp_stx_parser_error_string (xp_stx_parser_t* parser)
XP_TEXT("message selector"),
XP_TEXT("temporary list not closed"),
XP_TEXT("invalid argument name"),
XP_TEXT("too many arguments"),
XP_TEXT("invalid expression start"),
XP_TEXT("no period at end of statement")
};
@ -145,30 +148,30 @@ static int __parse_message_pattern (xp_stx_parser_t* parser)
* <keyword pattern> ::= (keyword <method argument>)+
*/
parser->argument_count = 0;
if (parser->token.type == XP_STX_TOKEN_IDENT) {
/* unary pattern */
xp_printf (XP_TEXT("unary pattern - %s\n"), parser->token.buffer);
GET_TOKEN (parser);
}
else if (parser->token.type == XP_STX_TOKEN_BINARY) {
/* binary pattern */
xp_printf (XP_TEXT("binary pattern - %s\n"), parser->token.buffer);
GET_TOKEN (parser);
if (parser->token.type != XP_STX_TOKEN_IDENT) {
parser->error_code = XP_STX_PARSER_ERROR_ARGUMENT;
parser->error_code = XP_STX_PARSER_ERROR_ARGUMENT_NAME;
return -1;
}
/* TODO: decide whether to use symbol */
//parser->arguments[parser->argument_count++] =
GET_TOKEN (parser);
}
else if (parser->token.type == XP_STX_TOKEN_KEYWORD) {
/* keyword pattern */
xp_printf (XP_TEXT("keyword pattern - %s\n"), parser->token.buffer);
do {
GET_TOKEN (parser);
if (parser->token.type != XP_STX_TOKEN_IDENT) {
parser->error_code = XP_STX_PARSER_ERROR_ARGUMENT;
parser->error_code = XP_STX_PARSER_ERROR_ARGUMENT_NAME;
return -1;
}
GET_TOKEN (parser);

View File

@ -1,5 +1,5 @@
/*
* $Id: parser.h,v 1.16 2005-06-12 12:33:31 bacon Exp $
* $Id: parser.h,v 1.17 2005-06-12 14:40:35 bacon Exp $
*/
#ifndef _XP_STX_PARSER_H_
@ -25,7 +25,8 @@ enum
/* syntatic error */
XP_STX_PARSER_ERROR_MESSAGE_SELECTOR,
XP_STX_PARSER_ERROR_TEMPORARIES_NOT_CLOSED,
XP_STX_PARSER_ERROR_ARGUMENT,
XP_STX_PARSER_ERROR_ARGUMENT_NAME,
XP_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS,
XP_STX_PARSER_ERROR_EXPRESSION_START,
XP_STX_PARSER_ERROR_NO_PERIOD
};
@ -44,10 +45,12 @@ typedef struct xp_stx_parser_t xp_stx_parser_t;
struct xp_stx_parser_t
{
xp_stx_t* stx;
int error_code;
xp_stx_token_t token;
xp_word_t argument[32];
xp_size_t argument_count;
xp_stx_token_t token;
xp_cint_t curc;
xp_cint_t ungotc[5];
xp_size_t ungotc_count;

View File

@ -1,5 +1,5 @@
/*
* $Id: token.c,v 1.5 2005-06-08 16:00:51 bacon Exp $
* $Id: token.c,v 1.6 2005-06-12 14:40:35 bacon Exp $
*/
#include <xp/stx/token.h>
@ -18,12 +18,17 @@ xp_stx_token_t* xp_stx_token_open (
}
else token->__malloced = xp_false;
if (capacity < xp_countof(token->static_buffer)) {
token->buffer = token->static_buffer;
}
else {
token->buffer = (xp_char_t*)
xp_malloc ((capacity + 1) * xp_sizeof(xp_char_t));
if (token->buffer == XP_NULL) {
if (token->__malloced) xp_free (token);
return XP_NULL;
}
}
/*
token->ivalue = 0;
@ -39,7 +44,10 @@ xp_stx_token_t* xp_stx_token_open (
void xp_stx_token_close (xp_stx_token_t* token)
{
if (token->capacity < xp_countof(token->static_buffer)) {
xp_assert (token->buffer != token->static_buffer);
xp_free (token->buffer);
}
if (token->__malloced) xp_free (token);
}
@ -47,11 +55,30 @@ int xp_stx_token_addc (xp_stx_token_t* token, xp_cint_t c)
{
if (token->size >= token->capacity) {
/* double the capacity. */
xp_char_t* space = (xp_char_t*)xp_realloc (
token->buffer, (token->capacity * 2 + 1) * xp_sizeof(xp_char_t));
xp_size_t new_capacity = token->capacity * 2;
if (new_capacity >= xp_countof(token->static_buffer)) {
xp_char_t* space;
if (token->capacity < xp_countof(token->static_buffer)) {
space = (xp_char_t*)xp_malloc (
(new_capacity + 1) * xp_sizeof(xp_char_t));
if (space == XP_NULL) return -1;
/* don't need to copy up to the terminating null */
xp_memcpy (space, token->buffer,
token->capacity * xp_sizeof(xp_char_t));
}
else {
space = (xp_char_t*)xp_realloc (token->buffer,
(new_capacity + 1) * xp_sizeof(xp_char_t));
if (space == XP_NULL) return -1;
}
token->buffer = space;
token->capacity = token->capacity * 2;
}
token->capacity = new_capacity;
}
token->buffer[token->size++] = c;
@ -74,11 +101,24 @@ xp_char_t* xp_stx_token_yield (xp_stx_token_t* token, xp_word_t capacity)
{
xp_char_t* old_buffer, * new_buffer;
if (token->capacity < xp_countof(token->static_buffer)) {
old_buffer = (xp_char_t*)
xp_malloc((token->capacity + 1) * xp_sizeof(xp_char_t));
if (old_buffer == XP_NULL) return XP_NULL;
xp_memcpy (old_buffer, token->buffer,
(token->capacity + 1) * xp_sizeof(xp_char_t));
}
else old_buffer = token->buffer;
if (capacity < xp_countof(token->static_buffer)) {
new_buffer = token->static_buffer;
}
else {
new_buffer = (xp_char_t*)
xp_malloc((capacity + 1) * xp_sizeof(xp_char_t));
if (new_buffer == XP_NULL) return XP_NULL;
}
old_buffer = token->buffer;
token->buffer = new_buffer;
token->size = 0;
token->capacity = capacity;

View File

@ -1,5 +1,5 @@
/*
* $Id: token.h,v 1.11 2005-06-12 12:33:31 bacon Exp $
* $Id: token.h,v 1.12 2005-06-12 14:40:35 bacon Exp $
*/
#ifndef _XP_STX_TOKEN_H_
@ -39,6 +39,7 @@ struct xp_stx_token_t
xp_word_t capacity;
xp_word_t size;
xp_char_t* buffer;
xp_char_t static_buffer[16];
xp_bool_t __malloced;
};