*** empty log message ***

This commit is contained in:
hyung-hwan 2005-06-12 15:46:02 +00:00
parent 036e2afef0
commit d2936c6b4c
6 changed files with 100 additions and 34 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parser.c,v 1.27 2005-06-12 14:40:35 bacon Exp $ * $Id: parser.c,v 1.28 2005-06-12 15:46:02 bacon Exp $
*/ */
#include <xp/stx/parser.h> #include <xp/stx/parser.h>
@ -9,7 +9,12 @@
static int __parse_method ( static int __parse_method (
xp_stx_parser_t* parser, xp_stx_parser_t* parser,
xp_word_t method_class, void* input); xp_word_t method_class, void* input);
static int __parse_message_pattern (xp_stx_parser_t* parser); static int __parse_message_pattern (xp_stx_parser_t* parser);
static int __parse_unary_pattern (xp_stx_parser_t* parser);
static int __parse_binary_pattern (xp_stx_parser_t* parser);
static int __parse_keyword_pattern (xp_stx_parser_t* parser);
static int __parse_temporaries (xp_stx_parser_t* parser); static int __parse_temporaries (xp_stx_parser_t* parser);
static int __parse_statements (xp_stx_parser_t* parser); static int __parse_statements (xp_stx_parser_t* parser);
static int __parse_statements_2 (xp_stx_parser_t* parser); static int __parse_statements_2 (xp_stx_parser_t* parser);
@ -38,7 +43,7 @@ xp_stx_parser_t* xp_stx_parser_open (xp_stx_parser_t* parser, xp_stx_t* stx)
} }
else parser->__malloced = xp_false; else parser->__malloced = xp_false;
if (xp_stx_token_open (&parser->token, 256) == XP_NULL) { if (xp_stx_token_open (&parser->token, 0) == XP_NULL) {
if (parser->__malloced) xp_free (parser); if (parser->__malloced) xp_free (parser);
return XP_NULL; return XP_NULL;
} }
@ -58,6 +63,10 @@ xp_stx_parser_t* xp_stx_parser_open (xp_stx_parser_t* parser, xp_stx_t* stx)
void xp_stx_parser_close (xp_stx_parser_t* parser) void xp_stx_parser_close (xp_stx_parser_t* parser)
{ {
while (parser->argument_count > 0) {
xp_free (parser->argument[--parser->argument_count]);
}
xp_stx_token_close (&parser->token); xp_stx_token_close (&parser->token);
if (parser->__malloced) xp_free (parser); if (parser->__malloced) xp_free (parser);
} }
@ -147,41 +156,94 @@ static int __parse_message_pattern (xp_stx_parser_t* parser)
* <binary pattern> ::= binarySelector <method argument> * <binary pattern> ::= binarySelector <method argument>
* <keyword pattern> ::= (keyword <method argument>)+ * <keyword pattern> ::= (keyword <method argument>)+
*/ */
int n;
parser->argument_count = 0; while (parser->argument_count > 0) {
xp_free (parser->argument[--parser->argument_count]);
}
if (parser->token.type == XP_STX_TOKEN_IDENT) { if (parser->token.type == XP_STX_TOKEN_IDENT) {
/* unary pattern */ n = __parse_unary_pattern (parser);
GET_TOKEN (parser);
} }
else if (parser->token.type == XP_STX_TOKEN_BINARY) { else if (parser->token.type == XP_STX_TOKEN_BINARY) {
/* binary pattern */ n = __parse_binary_pattern (parser);
}
else if (parser->token.type == XP_STX_TOKEN_KEYWORD) {
n = __parse_keyword_pattern (parser);
}
else {
parser->error_code = XP_STX_PARSER_ERROR_MESSAGE_SELECTOR;
n = -1;
}
return n;
}
static int __parse_unary_pattern (xp_stx_parser_t* parser)
{
/* TODO: check if the method name exists */
GET_TOKEN (parser);
return 0;
}
static int __parse_binary_pattern (xp_stx_parser_t* parser)
{
/* TODO: check if the method name exists */
GET_TOKEN (parser); GET_TOKEN (parser);
if (parser->token.type != XP_STX_TOKEN_IDENT) { if (parser->token.type != XP_STX_TOKEN_IDENT) {
parser->error_code = XP_STX_PARSER_ERROR_ARGUMENT_NAME; parser->error_code = XP_STX_PARSER_ERROR_ARGUMENT_NAME;
return -1; return -1;
} }
/* TODO: decide whether to use symbol */ if (parser->argument_count >= xp_countof(parser->argument)) {
//parser->arguments[parser->argument_count++] = parser->error_code = XP_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS;
GET_TOKEN (parser); return -1;
} }
else if (parser->token.type == XP_STX_TOKEN_KEYWORD) {
/* keyword pattern */ /* TODO: decide whether to use symbol */
parser->argument[parser->argument_count] =
xp_stx_token_yield (&parser->token, 0);
if (parser->argument[parser->argument_count] == XP_NULL) {
parser->error_code = XP_STX_PARSER_ERROR_MEMORY;
return -1;
}
parser->argument_count++;
GET_TOKEN (parser);
return 0;
}
static int __parse_keyword_pattern (xp_stx_parser_t* parser)
{
do { do {
GET_TOKEN (parser); GET_TOKEN (parser);
if (parser->token.type != XP_STX_TOKEN_IDENT) { if (parser->token.type != XP_STX_TOKEN_IDENT) {
parser->error_code = XP_STX_PARSER_ERROR_ARGUMENT_NAME; parser->error_code = XP_STX_PARSER_ERROR_ARGUMENT_NAME;
return -1; return -1;
} }
GET_TOKEN (parser);
} while (parser->token.type == XP_STX_TOKEN_KEYWORD); if (parser->argument_count >= xp_countof(parser->argument)) {
} parser->error_code = XP_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS;
else {
parser->error_code = XP_STX_PARSER_ERROR_MESSAGE_SELECTOR;
return -1; return -1;
} }
/* TODO: decide whether to use symbol */
parser->argument[parser->argument_count] =
xp_stx_token_yield (&parser->token, 0);
if (parser->argument[parser->argument_count] == XP_NULL) {
parser->error_code = XP_STX_PARSER_ERROR_MEMORY;
return -1;
}
/* TODO: check for duplicate entries... */
parser->argument_count++;
GET_TOKEN (parser);
} while (parser->token.type == XP_STX_TOKEN_KEYWORD);
/* TODO: check if the method name exists */
/* if it exists, collapse arguments */
return 0; return 0;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parser.h,v 1.17 2005-06-12 14:40:35 bacon Exp $ * $Id: parser.h,v 1.18 2005-06-12 15:46:02 bacon Exp $
*/ */
#ifndef _XP_STX_PARSER_H_ #ifndef _XP_STX_PARSER_H_
@ -47,7 +47,7 @@ struct xp_stx_parser_t
xp_stx_t* stx; xp_stx_t* stx;
int error_code; int error_code;
xp_word_t argument[32]; xp_char_t* argument[32];
xp_size_t argument_count; xp_size_t argument_count;
xp_stx_token_t token; xp_stx_token_t token;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: token.c,v 1.6 2005-06-12 14:40:35 bacon Exp $ * $Id: token.c,v 1.7 2005-06-12 15:46:02 bacon Exp $
*/ */
#include <xp/stx/token.h> #include <xp/stx/token.h>
@ -8,7 +8,8 @@
xp_stx_token_t* xp_stx_token_open ( xp_stx_token_t* xp_stx_token_open (
xp_stx_token_t* token, xp_word_t capacity) xp_stx_token_t* token, xp_word_t capacity)
{ {
xp_assert (capacity > 0); if (capacity == 0)
capacity = xp_countof(token->static_buffer) - 1;
if (token == XP_NULL) { if (token == XP_NULL) {
token = (xp_stx_token_t*) token = (xp_stx_token_t*)
@ -44,7 +45,7 @@ xp_stx_token_t* xp_stx_token_open (
void xp_stx_token_close (xp_stx_token_t* token) void xp_stx_token_close (xp_stx_token_t* token)
{ {
if (token->capacity < xp_countof(token->static_buffer)) { if (token->capacity >= xp_countof(token->static_buffer)) {
xp_assert (token->buffer != token->static_buffer); xp_assert (token->buffer != token->static_buffer);
xp_free (token->buffer); xp_free (token->buffer);
} }
@ -101,6 +102,9 @@ xp_char_t* xp_stx_token_yield (xp_stx_token_t* token, xp_word_t capacity)
{ {
xp_char_t* old_buffer, * new_buffer; xp_char_t* old_buffer, * new_buffer;
if (capacity == 0)
capacity = xp_countof(token->static_buffer) - 1;
if (token->capacity < xp_countof(token->static_buffer)) { if (token->capacity < xp_countof(token->static_buffer)) {
old_buffer = (xp_char_t*) old_buffer = (xp_char_t*)
xp_malloc((token->capacity + 1) * xp_sizeof(xp_char_t)); xp_malloc((token->capacity + 1) * xp_sizeof(xp_char_t));

View File

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

View File

@ -6,13 +6,13 @@ LIBS = @LIBS@ -lxpstx -lxpbas
all: stx parser all: stx parser
stx: stx.o stx: stx.o
$(CC) $(LDFLAGS) -o $@ $< $(LIBS) $(CC) $(LDFLAGS) -o $@.x $< $(LIBS)
parser: parser.o parser: parser.o
$(CC) $(LDFLAGS) -o $@ $< $(LIBS) $(CC) $(LDFLAGS) -o $@.x $< $(LIBS)
clean: clean:
rm -rf $(OUTS) *.o rm -rf *.x *.o
.SUFFIXES: .c .o .SUFFIXES: .c .o
.c.o: .c.o:

View File

@ -1,5 +1,5 @@
"isNil" "test if self is nil" "isNil" "test if self is nil"
perform: method with: x with: y perform: method with: x with: y with: z with: a with: b with: c
| a b c d e f g | | a b c d e f g |
'this is very bad''this is'. 'this is very bad''this is'.