From ad0c9a26dc58bef91cf312b744e171154ab7f59f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 22 Jun 2005 15:02:41 +0000 Subject: [PATCH] *** empty log message *** --- ase/stx/parser.c | 123 ++++++++++++++++++++++---------------- ase/test/stx/makefile.lcc | 2 +- ase/test/stx/test.st | 2 +- 3 files changed, 72 insertions(+), 55 deletions(-) diff --git a/ase/stx/parser.c b/ase/stx/parser.c index d32260dd..51d66aca 100644 --- a/ase/stx/parser.c +++ b/ase/stx/parser.c @@ -1,5 +1,5 @@ /* - * $Id: parser.c,v 1.36 2005-06-19 16:16:33 bacon Exp $ + * $Id: parser.c,v 1.37 2005-06-22 15:02:41 bacon Exp $ */ #include @@ -27,7 +27,7 @@ static int __parse_binary_continuation (xp_stx_parser_t* parser); static int __parse_unary_continuation (xp_stx_parser_t* parser); static int __emit_code ( - xp_stx_parser_t* parser, const xp_char_t* high, int low); + xp_stx_parser_t* parser, const xp_char_t* high, const xp_char_t* low); static int __get_token (xp_stx_parser_t* parser); static int __get_ident (xp_stx_parser_t* parser); @@ -421,9 +421,6 @@ static int __parse_expression (xp_stx_parser_t* parser) * ::= [ ] * := identifier * assignmentOperator ::= ':=' - * ::= - * identifier | | - * | ( '('')' ) */ if (parser->token.type == XP_STX_TOKEN_IDENT) { @@ -444,25 +441,43 @@ static int __parse_expression (xp_stx_parser_t* parser) } else { if (__parse_message_continuation(parser) == -1) { - return -1; xp_free (ident); + return -1; } } xp_free (ident); } + else { + parser->error_code = XP_STX_PARSER_ERROR_EXPRESSION_START; + return -1; + } + + return 0; +} + +static int __parse_primary (xp_stx_parser_t* parser) +{ + /* + * ::= + * identifier | | + * | ( '('')' ) + */ + + if (parser->token.type == XP_STX_TOKEN_IDENT) { + } else if (parser->token.type == XP_STX_TOKEN_CHARLIT) { - EMIT_CODE (parser, XP_TEXT("PushLiteral(CHAR)"), 0xFFFF); + EMIT_CODE (parser, XP_TEXT("PushLiteral(CHAR)"), parser->token.name.buffer); GET_TOKEN (parser); if (__parse_message_continuation(parser) == -1) return -1; } else if (parser->token.type == XP_STX_TOKEN_STRLIT) { - EMIT_CODE (parser, XP_TEXT("PushLiteral(STR)"), 0xFFFF); + EMIT_CODE (parser, XP_TEXT("PushLiteral(STR)"), parser->token.name.buffer); GET_TOKEN (parser); if (__parse_message_continuation(parser) == -1) return -1; } else if (parser->token.type == XP_STX_TOKEN_NUMLIT) { - EMIT_CODE (parser, XP_TEXT("PushLiteral(NUM)"), 0xFFFF); + EMIT_CODE (parser, XP_TEXT("PushLiteral(NUM)"), parser->token.name.buffer); GET_TOKEN (parser); if (__parse_message_continuation(parser) == -1) return -1; } @@ -472,12 +487,12 @@ static int __parse_expression (xp_stx_parser_t* parser) else if (parser->token.type == XP_STX_TOKEN_LPAREN) { } else { +/* TODO: maybe invalid primary */ parser->error_code = XP_STX_PARSER_ERROR_EXPRESSION_START; return -1; } - - return 0; } + /* &unsupportedByte, //--- 00 &bytePushInstance, //--- 01 @@ -519,37 +534,6 @@ AssignInstance AssignTemporary */ -static int __identify_ident (xp_stx_parser_t* parser, const xp_char_t* ident) -{ - xp_size_t i; - - if (xp_strcmp(ident, XP_TEXT("self")) == 0) { - } - - if (xp_strcmp(ident, XP_TEXT("super")) == 0) { - } - - for (i = 0; i < parser->temporary_count; i++) { - if (xp_strcmp (parser->temporary[i], ident) == 0) { - } - } - - for (i = 0; i < parser->argument_count; i++) { - if (xp_strcmp (parser->argument[i], ident) == 0) { - } - } - - /* TODO; find it in intance variables names */ - - /* TODO; find it in class variables names */ - - /* TODO; find it in global variables */ - - /* TODO: dynamic global */ - - return 0; -} - static int __parse_assignment ( xp_stx_parser_t* parser, const xp_char_t* target) { @@ -561,8 +545,11 @@ static int __parse_assignment ( for (i = 0; i < parser->temporary_count; i++) { if (xp_strcmp (target, parser->temporary[i]) == 0) { +xp_char_t buf[100]; if (__parse_expression(parser) == -1) return -1; - EMIT_CODE (parser, XP_TEXT("AssignTemporary"), i); + +xp_sprintf (buf, xp_countof(buf), XP_TEXT("%d"), i); + EMIT_CODE (parser, XP_TEXT("AssignTemporary"), buf); return 0; } } @@ -578,14 +565,30 @@ static int __parse_assignment ( static int __parse_message_continuation (xp_stx_parser_t* parser) { - if (__parse_keyword_continuation (parser) == -1) return -1; + + /* + * ::= + * [ ] + * ::= + * (+ * [] ) | + * (+ [] ) | + * + * ::= unarySelector + * ::= binarySelector + * ::= * + * ::= (keyword )+ + * ::= * * + * ::= (';' )* + */ + + if (__parse_keyword_continuation(parser) == -1) return -1; while (parser->token.type == XP_STX_TOKEN_SEMICOLON) { - EMIT_CODE (parser, XP_TEXT("DoSpecial(DUP_RECEIVER)"), 0); + EMIT_CODE (parser, XP_TEXT("DoSpecial(DUP_RECEIVER)"), XP_TEXT("")); GET_TOKEN (parser); if (__parse_keyword_continuation (parser) == -1) return -1; - EMIT_CODE (parser, XP_TEXT("DoSpecial(POP_TOP)"), 0); + EMIT_CODE (parser, XP_TEXT("DoSpecial(POP_TOP)"), XP_TEXT("")); } return 0; @@ -593,29 +596,43 @@ static int __parse_message_continuation (xp_stx_parser_t* parser) static int __parse_keyword_continuation (xp_stx_parser_t* parser) { - if (__parser_binary_continuation (parser) == -1) return -1; - return -1; + if (__parse_binary_continuation (parser) == -1) return -1; + return 0; } static int __parse_binary_continuation (xp_stx_parser_t* parser) { - if (__parser_unary_continuation (parser) == -1) return -1; - return -1; + /* + * ::= binarySelector + * ::= * + */ + + if (__parse_unary_continuation (parser) == -1) return -1; + + while (parser->token.type == XP_STX_TOKEN_BINARY) { + EMIT_CODE (parser, XP_TEXT("SendBinary"), parser->token.name.buffer); + GET_TOKEN (parser); + } + + return 0; } static int __parse_unary_continuation (xp_stx_parser_t* parser) { - while (parser->token.type == XP_STX_TOKEN_IDENT) { + /* ::= unarySelector */ + while (parser->token.type == XP_STX_TOKEN_IDENT) { + EMIT_CODE (parser, XP_TEXT("SendUnary"), parser->token.name.buffer); + GET_TOKEN (parser); } return 0; } static int __emit_code ( - xp_stx_parser_t* parser, const xp_char_t* high, int low) + xp_stx_parser_t* parser, const xp_char_t* high, const xp_char_t* low) { - xp_printf (XP_TEXT("CODE: %s %d\n"), high, low); + xp_printf (XP_TEXT("CODE: %s %s\n"), high, low); return 0; } diff --git a/ase/test/stx/makefile.lcc b/ase/test/stx/makefile.lcc index 91e993c5..e14a27a8 100644 --- a/ase/test/stx/makefile.lcc +++ b/ase/test/stx/makefile.lcc @@ -3,7 +3,7 @@ CFLAGS = -I../../.. -A -ansic -libcdll #LDFLAGS = -L../../../xp/bas -L../../../xp/stx #LIBS = -lxpstx -lxpbas LDFLAGS = -subsystem console -dynamic -s -LIBS = ..\..\..\xp\bas\xpbas.lib ..\..\..\xp\stx\xpstx.lib +LIBS = ..\..\..\xp\stx\xpstx.lib ..\..\..\xp\bas\xpbas.lib all: stx parser diff --git a/ase/test/stx/test.st b/ase/test/stx/test.st index d753c4d6..191b1db2 100644 --- a/ase/test/stx/test.st +++ b/ase/test/stx/test.st @@ -4,7 +4,7 @@ perform: method with: x with: y with: z with: a with: b with: c | a b c d e f g | a := 'this is ''good'. - b := -30. + b := -30 xxx nil this. " $a.