diff --git a/ase/stx/parser.c b/ase/stx/parser.c index ad46f5e1..ca4d967b 100644 --- a/ase/stx/parser.c +++ b/ase/stx/parser.c @@ -1,5 +1,5 @@ /* - * $Id: parser.c,v 1.22 2005-06-08 03:19:31 bacon Exp $ + * $Id: parser.c,v 1.23 2005-06-08 15:49:35 bacon Exp $ */ #include @@ -18,6 +18,7 @@ static int __get_ident (xp_stx_parser_t* parser); static int __get_numlit (xp_stx_parser_t* parser, xp_bool_t negated); static int __get_charlit (xp_stx_parser_t* parser); static int __get_strlit (xp_stx_parser_t* parser); +static int __get_binary (xp_stx_parser_t* parser); static int __skip_spaces (xp_stx_parser_t* parser); static int __skip_comment (xp_stx_parser_t* parser); static int __get_char (xp_stx_parser_t* parser); @@ -149,6 +150,26 @@ static int __parse_statements (xp_stx_parser_t* parser) return -1; } +static inline xp_bool_t __is_binary_char (xp_cint_t c) +{ + /* + * binaryCharacter ::= + * '!' | '%' | '&' | '*' | '+' | ',' | + * '/' | '<' | '=' | '>' | '?' | '@' | + * '\' | '~' | '|' | '-' + */ + + return + c == XP_STX_CHAR('!') || c == XP_STX_CHAR('%') || + c == XP_STX_CHAR('&') || c == XP_STX_CHAR('*') || + c == XP_STX_CHAR('+') || c == XP_STX_CHAR(',') || + c == XP_STX_CHAR('/') || c == XP_STX_CHAR('<') || + c == XP_STX_CHAR('=') || c == XP_STX_CHAR('>') || + c == XP_STX_CHAR('?') || c == XP_STX_CHAR('@') || + c == XP_STX_CHAR('\\') || c == XP_STX_CHAR('|') || + c == XP_STX_CHAR('~') || c == XP_STX_CHAR('-'); +} + static int __get_token (xp_stx_parser_t* parser) { xp_cint_t c; @@ -174,16 +195,6 @@ static int __get_token (xp_stx_parser_t* parser) else if (xp_stx_isdigit(c)) { if (__get_numlit(parser, xp_false) == -1) return -1; } - else if (c == XP_STX_CHAR('-')) { - parser->token.type = XP_STX_TOKEN_MINUS; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - - c = parser->curc; - if (xp_stx_isdigit(c)) { - if (__get_numlit(parser,xp_true) == -1) return -1; - } - } else if (c == XP_STX_CHAR('$')) { GET_CHAR (parser); if (__get_charlit(parser) == -1) return -1; @@ -229,6 +240,9 @@ static int __get_token (xp_stx_parser_t* parser) ADD_TOKEN_CHAR(parser, c); GET_CHAR (parser); } + else if (__is_binary_char(c)) { + if (__get_binary(parser) == -1) return -1; + } else { parser->error_code = XP_STX_PARSER_ERROR_CHAR; return -1; @@ -345,6 +359,46 @@ static int __get_strlit (xp_stx_parser_t* parser) return 0; } +static int __get_binary (xp_stx_parser_t* parser) +{ + /* + * binarySelector ::= binaryCharacter+ + */ + + xp_cint_t c = parser->curc; + + ADD_TOKEN_CHAR (parser, c); + + if (c == XP_STX_CHAR('<')) { +/* + const xp_stx_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_STX_CHAR('-')) { + GET_CHAR (parser); + c = parser->curc; + if (xp_stx_isdigit(c)) return __get_numlit(parser,xp_true); + } + else { + GET_CHAR (parser); + c = parser->curc; + } + + if (__is_binary_char(c)) { + ADD_TOKEN_CHAR (parser, c); + GET_CHAR (parser); + } + + parser->token.type = XP_STX_TOKEN_BINARY; + return 0; +} + static int __skip_spaces (xp_stx_parser_t* parser) { while (xp_stx_isspace(parser->curc)) GET_CHAR (parser); diff --git a/ase/stx/stx.h b/ase/stx/stx.h index 828d0427..aa44cab9 100644 --- a/ase/stx/stx.h +++ b/ase/stx/stx.h @@ -1,5 +1,5 @@ /* - * $Id: stx.h,v 1.24 2005-06-05 05:26:24 bacon Exp $ + * $Id: stx.h,v 1.25 2005-06-08 15:49:35 bacon Exp $ */ #ifndef _XP_STX_STX_H_ @@ -8,10 +8,10 @@ #include #include -typedef xp_byte_t xp_stx_byte_t; -typedef xp_char_t xp_stx_char_t; +typedef xp_byte_t xp_byte_t; +typedef xp_char_t xp_char_t; typedef xp_cint_t xp_stx_cint_t; -typedef xp_size_t xp_stx_word_t; +typedef xp_word_t xp_word_t; typedef struct xp_stx_objhdr_t xp_stx_objhdr_t; typedef struct xp_stx_object_t xp_stx_object_t; @@ -31,8 +31,8 @@ struct xp_stx_objhdr_t /* access - type: 2; size: rest; * type - word indexed: 00 byte indexed: 01 char indexed: 10 */ - xp_stx_word_t access; - xp_stx_word_t class; + xp_word_t access; + xp_word_t class; }; struct xp_stx_object_t @@ -43,24 +43,24 @@ struct xp_stx_object_t struct xp_stx_word_object_t { xp_stx_objhdr_t header; - xp_stx_word_t data[1]; + xp_word_t data[1]; }; struct xp_stx_byte_object_t { xp_stx_objhdr_t header; - xp_stx_byte_t data[1]; + xp_byte_t data[1]; }; struct xp_stx_char_object_t { xp_stx_objhdr_t header; - xp_stx_char_t data[1]; + xp_char_t data[1]; }; struct xp_stx_memory_t { - xp_stx_word_t capacity; + xp_word_t capacity; xp_stx_object_t** slots; xp_stx_object_t** free; xp_bool_t __malloced; @@ -70,21 +70,21 @@ struct xp_stx_t { xp_stx_memory_t memory; - xp_stx_word_t nil; - xp_stx_word_t true; - xp_stx_word_t false; + xp_word_t nil; + xp_word_t true; + xp_word_t false; - xp_stx_word_t symbol_table; - xp_stx_word_t smalltalk; + xp_word_t symbol_table; + xp_word_t smalltalk; - xp_stx_word_t class_symlink; - xp_stx_word_t class_symbol; - xp_stx_word_t class_metaclass; - xp_stx_word_t class_pairlink; + xp_word_t class_symlink; + xp_word_t class_symbol; + xp_word_t class_metaclass; + xp_word_t class_pairlink; - xp_stx_word_t class_object; - xp_stx_word_t class_class; - xp_stx_word_t class_array; + xp_word_t class_object; + xp_word_t class_class; + xp_word_t class_array; xp_bool_t __malloced; xp_bool_t __wantabort; /* TODO: make it a function pointer */ @@ -115,17 +115,17 @@ typedef xp_stx_cint_t (*xp_stx_getc_t) (void*); ((xp_stx_char_object_t*)XP_STX_OBJECT(stx,idx)) #define XP_STX_WORDAT(stx,idx,n) \ - (((xp_stx_word_t*)(XP_STX_OBJECT(stx,idx) + 1))[n]) + (((xp_word_t*)(XP_STX_OBJECT(stx,idx) + 1))[n]) #define XP_STX_BYTEAT(stx,idx,n) \ - (((xp_stx_byte_t*)(XP_STX_OBJECT(stx,idx) + 1))[n]) + (((xp_byte_t*)(XP_STX_OBJECT(stx,idx) + 1))[n]) #define XP_STX_CHARAT(stx,idx,n) \ - (((xp_stx_char_t*)(XP_STX_OBJECT(stx,idx) + 1))[n]) + (((xp_char_t*)(XP_STX_OBJECT(stx,idx) + 1))[n]) #ifdef __cplusplus extern "C" { #endif -xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity); +xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_word_t capacity); void xp_stx_close (xp_stx_t* stx); int xp_stx_bootstrap (xp_stx_t* stx); diff --git a/ase/stx/token.h b/ase/stx/token.h index 658e3c21..bd9ab84d 100644 --- a/ase/stx/token.h +++ b/ase/stx/token.h @@ -1,5 +1,5 @@ /* - * $Id: token.h,v 1.7 2005-06-08 03:16:34 bacon Exp $ + * $Id: token.h,v 1.8 2005-06-08 15:49:35 bacon Exp $ */ #ifndef _XP_STX_TOKEN_H_ @@ -16,14 +16,14 @@ enum XP_STX_TOKEN_IDENT, XP_STX_TOKEN_BINARY, XP_STX_TOKEN_KEYWORD, - XP_STX_TOKEN_MINUS, + XP_STX_TOKEN_PRIMITIVE, 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, + XP_STX_TOKEN_PERIOD }; struct xp_stx_token_t diff --git a/ase/types.h b/ase/types.h index 984183c2..77ef6e39 100644 --- a/ase/types.h +++ b/ase/types.h @@ -1,5 +1,5 @@ /* - * $Id: types.h,v 1.27 2005-06-06 16:32:29 bacon Exp $ + * $Id: types.h,v 1.28 2005-06-08 15:49:35 bacon Exp $ */ #ifndef _XP_TYPES_H_ @@ -116,6 +116,7 @@ typedef int xp_tri_t; typedef xp_uint8_t xp_byte_t; typedef xp_uint_t xp_size_t; typedef xp_int_t xp_ssize_t; +typedef xp_uint_t xp_word_t; /* floating-point number */ #if SIZEOF_LONG_DOUBLE > SIZEOF_DOUBLE