*** empty log message ***

This commit is contained in:
hyung-hwan 2005-06-11 18:01:25 +00:00
parent 29877d7513
commit 50e417a34d
5 changed files with 75 additions and 36 deletions

View File

@ -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 <xp/stx/parser.h> #include <xp/stx/parser.h>
@ -12,6 +12,7 @@ static int __parse_method (
static int __parse_message_pattern (xp_stx_parser_t* parser); static int __parse_message_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_expression (xp_stx_parser_t* parser);
static int __get_token (xp_stx_parser_t* parser); static int __get_token (xp_stx_parser_t* parser);
static int __get_ident (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) { if (parser->token.type == XP_STX_TOKEN_IDENT) {
/* unary pattern */ /* 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) { else if (parser->token.type == XP_STX_TOKEN_BINARY) {
/* binary pattern */ /* binary pattern */
xp_printf (XP_TEXT("binary pattern - %s\n"), parser->token.buffer);
} }
else if (parser->token.type == XP_STX_TOKEN_KEYWORD) { else if (parser->token.type == XP_STX_TOKEN_KEYWORD) {
/* keyword pattern */ /* keyword pattern */
xp_char_t* selector; xp_printf (XP_TEXT("keyword pattern - %s\n"), parser->token.buffer);
} }
else { else {
parser->error_code = XP_STX_PARSER_ERROR_MESSAGE_SELECTOR; parser->error_code = XP_STX_PARSER_ERROR_MESSAGE_SELECTOR;
return -1; 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; 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) static int __parse_temporaries (xp_stx_parser_t* parser)
{ {
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; return -1;
} }
GET_TOKEN (parser);
return 0;
}
static int __parse_statements (xp_stx_parser_t* parser) static int __parse_statements (xp_stx_parser_t* parser)
{
/*
* <statements> ::=
* (<return statement> ['.'] ) |
* (<expression> ['.' [<statements>]])
* <return statement> ::= returnOperator <expression>
* 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; return -1;
} }
@ -220,11 +264,6 @@ static int __get_token (xp_stx_parser_t* parser)
ADD_TOKEN_CHAR(parser, c); ADD_TOKEN_CHAR(parser, c);
GET_CHAR (parser); 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('[')) { else if (c == XP_CHAR('[')) {
parser->token.type = XP_STX_TOKEN_LBRACKET; parser->token.type = XP_STX_TOKEN_LBRACKET;
ADD_TOKEN_CHAR(parser, c); ADD_TOKEN_CHAR(parser, c);
@ -366,21 +405,9 @@ static int __get_binary (xp_stx_parser_t* parser)
*/ */
xp_cint_t c = parser->curc; xp_cint_t c = parser->curc;
ADD_TOKEN_CHAR (parser, c); ADD_TOKEN_CHAR (parser, c);
if (c == XP_CHAR('<')) { 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('-')) {
GET_CHAR (parser); GET_CHAR (parser);
c = parser->curc; c = parser->curc;
if (xp_isdigit(c)) return __get_numlit(parser,xp_true); 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; c = parser->curc;
} }
/* up to 2 characters only */
if (__is_binary_char(c)) { if (__is_binary_char(c)) {
ADD_TOKEN_CHAR (parser, c); ADD_TOKEN_CHAR (parser, c);
GET_CHAR (parser); 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; parser->token.type = XP_STX_TOKEN_BINARY;
return 0; return 0;
} }

View File

@ -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_ #ifndef _XP_STX_PARSER_H_
@ -23,7 +23,8 @@ enum
XP_STX_PARSER_ERROR_STRLIT, XP_STX_PARSER_ERROR_STRLIT,
/* syntatic error */ /* syntatic error */
XP_STX_PARSER_ERROR_MESSAGE_SELECTOR XP_STX_PARSER_ERROR_MESSAGE_SELECTOR,
XP_STX_PARSER_ERROR_TEMPORARIES_NOT_CLOSED
}; };
enum enum

View File

@ -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_ #ifndef _XP_STX_TOKEN_H_
@ -9,7 +9,7 @@
enum enum
{ {
XP_STX_TOKEN_END = 0, XP_STX_TOKEN_END,
XP_STX_TOKEN_CHARLIT, XP_STX_TOKEN_CHARLIT,
XP_STX_TOKEN_STRLIT, XP_STX_TOKEN_STRLIT,
XP_STX_TOKEN_NUMLIT, XP_STX_TOKEN_NUMLIT,
@ -20,7 +20,6 @@ enum
XP_STX_TOKEN_ASSIGN, XP_STX_TOKEN_ASSIGN,
XP_STX_TOKEN_COLON, XP_STX_TOKEN_COLON,
XP_STX_TOKEN_RETURN, XP_STX_TOKEN_RETURN,
XP_STX_TOKEN_BAR,
XP_STX_TOKEN_LBRACKET, XP_STX_TOKEN_LBRACKET,
XP_STX_TOKEN_RBRACKET, XP_STX_TOKEN_RBRACKET,
XP_STX_TOKEN_PERIOD XP_STX_TOKEN_PERIOD

View File

@ -126,7 +126,7 @@ int xp_main (int argc, xp_char_t* argv[])
parser.input_func = stdio_func; parser.input_func = stdio_func;
if (xp_stx_parser_parse_method (&parser, 0, if (xp_stx_parser_parse_method (&parser, 0,
(void*)XP_TEXT("test.st")) == -1) { (void*)XP_TEXT("test.st")) == -1) {
xp_printf (XP_TEXT("parser error\n")); xp_printf (XP_TEXT("parser error <%d>\n"), parser.error_code);
} }
} }

View File

@ -1,5 +1,6 @@
isNil isNil "test if self is nil"
"test if self is nil"
| a b c d e f g |
'this is very bad''this is' 'this is very bad''this is'
$a $b $a $b
^true $ ^true $