From 50e417a34d879166b84485bbf73237aa7e6de168 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 11 Jun 2005 18:01:25 +0000 Subject: [PATCH] *** empty log message *** --- ase/stx/parser.c | 94 ++++++++++++++++++++++++++++++------------- ase/stx/parser.h | 5 ++- ase/stx/token.h | 5 +-- ase/test/stx/parser.c | 2 +- ase/test/stx/test.st | 5 ++- 5 files changed, 75 insertions(+), 36 deletions(-) diff --git a/ase/stx/parser.c b/ase/stx/parser.c index 8f10669e..07f76c18 100644 --- a/ase/stx/parser.c +++ b/ase/stx/parser.c @@ -1,5 +1,5 @@ /* - * $Id: parser.c,v 1.24 2005-06-08 16:00:51 bacon Exp $ + * $Id: parser.c,v 1.25 2005-06-11 18:01:25 bacon Exp $ */ #include @@ -12,6 +12,7 @@ static int __parse_method ( static int __parse_message_pattern (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_expression (xp_stx_parser_t* parser); static int __get_token (xp_stx_parser_t* parser); static int __get_ident (xp_stx_parser_t* parser); @@ -118,34 +119,77 @@ static int __parse_message_pattern (xp_stx_parser_t* parser) 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); } else if (parser->token.type == XP_STX_TOKEN_KEYWORD) { /* keyword pattern */ - xp_char_t* selector; +xp_printf (XP_TEXT("keyword pattern - %s\n"), parser->token.buffer); } else { parser->error_code = XP_STX_PARSER_ERROR_MESSAGE_SELECTOR; return -1; } -/* - while (parser->token.type != XP_STX_TOKEN_END) { - xp_printf (XP_TEXT("token: [%s] %d\n"), - parser->token.buffer, parser->token.type); - GET_TOKEN (parser); - } -*/ + return 0; } +static inline xp_bool_t __is_vbar_token (const xp_stx_token_t* token) +{ + return + token->type == XP_STX_TOKEN_BINARY && + token->size == 1 && + token->buffer[0] == XP_CHAR('|'); +} + static int __parse_temporaries (xp_stx_parser_t* parser) { - return -1; + if (!__is_vbar_token(&parser->token)) return 0; + + GET_TOKEN (parser); + while (parser->token.type == XP_STX_TOKEN_IDENT) { +xp_printf (XP_TEXT("temporary: %s\n"), parser->token.buffer); + GET_TOKEN (parser); + } + if (!__is_vbar_token(&parser->token)) { + parser->error_code = XP_STX_PARSER_ERROR_TEMPORARIES_NOT_CLOSED; + return -1; + } + + GET_TOKEN (parser); + return 0; } static int __parse_statements (xp_stx_parser_t* parser) +{ + /* + * ::= + * ( ['.'] ) | + * ( ['.' []]) + * ::= returnOperator + * returnOperator ::= '^' + */ + + if (parser->token.type == XP_STX_TOKEN_RETURN) { + if (__parse_expresssion (parser) == -1) return -1; + /* TODO */ + } + else { + if (__parse_expresssion (parser) == -1) return -1; + if (parser->token.type == XP_STX_TOKEN_PERIOD) { + GET_TOKEN(parser); + if (__parse_statements (parser) == -1) return -1; + } + } + + return 0; +} + +static int __parse_expression (xp_stx_parser_t* parser) { return -1; } @@ -220,11 +264,6 @@ static int __get_token (xp_stx_parser_t* parser) ADD_TOKEN_CHAR(parser, c); GET_CHAR (parser); } - else if (c == XP_CHAR('|')) { - parser->token.type = XP_STX_TOKEN_BAR; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - } else if (c == XP_CHAR('[')) { parser->token.type = XP_STX_TOKEN_LBRACKET; ADD_TOKEN_CHAR(parser, c); @@ -366,21 +405,9 @@ static int __get_binary (xp_stx_parser_t* parser) */ xp_cint_t c = parser->curc; - ADD_TOKEN_CHAR (parser, c); - if (c == XP_CHAR('<')) { -/* - const xp_char_t* p = XP_TEXT("primitive:"); - - do { - GET_CHAR (parser); - c = parser->curc; - if (c == 'p') return __get_primitive (parser); - } while (*c) -*/ - } - else if (c == XP_CHAR('-')) { + if (c == XP_CHAR('-')) { GET_CHAR (parser); c = parser->curc; if (xp_isdigit(c)) return __get_numlit(parser,xp_true); @@ -390,11 +417,22 @@ static int __get_binary (xp_stx_parser_t* parser) c = parser->curc; } + /* up to 2 characters only */ if (__is_binary_char(c)) { ADD_TOKEN_CHAR (parser, c); GET_CHAR (parser); + c = parser->curc; } + /* or up to any occurrences */ + /* + while (__is_binary_char(c)) { + ADD_TOKEN_CHAR (parser, c); + GET_CHAR (parser); + c = parser->curc; + } + */ + parser->token.type = XP_STX_TOKEN_BINARY; return 0; } diff --git a/ase/stx/parser.h b/ase/stx/parser.h index da953947..f3bf9d3f 100644 --- a/ase/stx/parser.h +++ b/ase/stx/parser.h @@ -1,5 +1,5 @@ /* - * $Id: parser.h,v 1.14 2005-06-08 16:00:51 bacon Exp $ + * $Id: parser.h,v 1.15 2005-06-11 18:01:25 bacon Exp $ */ #ifndef _XP_STX_PARSER_H_ @@ -23,7 +23,8 @@ enum XP_STX_PARSER_ERROR_STRLIT, /* syntatic error */ - XP_STX_PARSER_ERROR_MESSAGE_SELECTOR + XP_STX_PARSER_ERROR_MESSAGE_SELECTOR, + XP_STX_PARSER_ERROR_TEMPORARIES_NOT_CLOSED }; enum diff --git a/ase/stx/token.h b/ase/stx/token.h index a6a5daa2..68267f8b 100644 --- a/ase/stx/token.h +++ b/ase/stx/token.h @@ -1,5 +1,5 @@ /* - * $Id: token.h,v 1.9 2005-06-08 16:00:51 bacon Exp $ + * $Id: token.h,v 1.10 2005-06-11 18:01:25 bacon Exp $ */ #ifndef _XP_STX_TOKEN_H_ @@ -9,7 +9,7 @@ enum { - XP_STX_TOKEN_END = 0, + XP_STX_TOKEN_END, XP_STX_TOKEN_CHARLIT, XP_STX_TOKEN_STRLIT, XP_STX_TOKEN_NUMLIT, @@ -20,7 +20,6 @@ enum XP_STX_TOKEN_ASSIGN, XP_STX_TOKEN_COLON, XP_STX_TOKEN_RETURN, - XP_STX_TOKEN_BAR, XP_STX_TOKEN_LBRACKET, XP_STX_TOKEN_RBRACKET, XP_STX_TOKEN_PERIOD diff --git a/ase/test/stx/parser.c b/ase/test/stx/parser.c index 958230cf..cde292e4 100644 --- a/ase/test/stx/parser.c +++ b/ase/test/stx/parser.c @@ -126,7 +126,7 @@ int xp_main (int argc, xp_char_t* argv[]) parser.input_func = stdio_func; if (xp_stx_parser_parse_method (&parser, 0, (void*)XP_TEXT("test.st")) == -1) { - xp_printf (XP_TEXT("parser error\n")); + xp_printf (XP_TEXT("parser error <%d>\n"), parser.error_code); } } diff --git a/ase/test/stx/test.st b/ase/test/stx/test.st index 7b4d6d8d..793f07e8 100644 --- a/ase/test/stx/test.st +++ b/ase/test/stx/test.st @@ -1,5 +1,6 @@ -isNil - "test if self is nil" +isNil "test if self is nil" + + | a b c d e f g | 'this is very bad''this is' $a $b ^true $