diff --git a/stix/lib/comp.c b/stix/lib/comp.c index 4a5ad05..3feaa3d 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -2169,9 +2169,10 @@ wprintf (L"METHOD NAME ==> [%S] temporaries => %d\n", fsc->met.name.buf, fsc->me enum class_mod_t { - BYTE_INDEXED = (1 << 0), - WORD_INDEXED = (1 << 1), - POINTER_INDEXED = (1 << 2) + CLASS_BYTE_INDEXED = (1 << 0), + CLASS_WORD_INDEXED = (1 << 1), + CLASS_POINTER_INDEXED = (1 << 2), + CLASS_EXTEND = (1 << 3) }; enum dcl_mod_t @@ -2209,6 +2210,10 @@ static int compile_class_declare (stix_t* stix) /* #dcl(#instance) */ dcl_mod &= ~(DCL_CLASS | DCL_CLASSINST); } + else + { + break; + } } while (1); @@ -2217,6 +2222,8 @@ static int compile_class_declare (stix_t* stix) set_syntax_error (stix, STIX_SYNERR_RPAREN, &stix->c->tok.loc, &stix->c->tok.name); return -1; } + + GET_TOKEN (stix); } do @@ -2272,20 +2279,20 @@ static int compile_class_definition (stix_t* stix) if (is_token_ksym(stix, KSYM_BYTE)) { /* #class(#byte) */ - class_mod &= ~(BYTE_INDEXED | WORD_INDEXED | POINTER_INDEXED); - class_mod |= BYTE_INDEXED; + class_mod &= ~(CLASS_BYTE_INDEXED | CLASS_WORD_INDEXED | CLASS_POINTER_INDEXED); + class_mod |= CLASS_BYTE_INDEXED; } else if (is_token_ksym(stix, KSYM_WORD)) { /* #class(#word) */ - class_mod &= ~(BYTE_INDEXED | WORD_INDEXED | POINTER_INDEXED); - class_mod |= WORD_INDEXED; + class_mod &= ~(CLASS_BYTE_INDEXED | CLASS_WORD_INDEXED | CLASS_POINTER_INDEXED); + class_mod |= CLASS_WORD_INDEXED; } else if (is_token_ksym(stix, KSYM_POINTER)) { /* #class(#pointer) */ - class_mod &= ~(BYTE_INDEXED | WORD_INDEXED | POINTER_INDEXED); - class_mod |= POINTER_INDEXED; + class_mod &= ~(CLASS_BYTE_INDEXED | CLASS_WORD_INDEXED | CLASS_POINTER_INDEXED); + class_mod |= CLASS_POINTER_INDEXED; } /* place other modifiers here */ else @@ -2315,19 +2322,45 @@ static int compile_class_definition (stix_t* stix) if (stix->c->tok.type == STIX_IOTOK_LPAREN) { - /* superclass is specified */ + /* superclass is specified. new class defintion. + * #class Class(Object) + */ + GET_TOKEN (stix); + + /* TODO: multiple inheritance */ + + if (stix->c->tok.type != STIX_IOTOK_IDENT) + { + /* superclass name expected */ + set_syntax_error (stix, STIX_SYNERR_IDENT, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + + GET_TOKEN (stix); + if (stix->c->tok.type != STIX_IOTOK_RPAREN) + { + set_syntax_error (stix, STIX_SYNERR_RPAREN, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + + GET_TOKEN (stix); } - + else + { + /* extending class */ + class_mod |= CLASS_EXTEND; + } + if (stix->c->tok.type != STIX_IOTOK_LBRACE) { set_syntax_error (stix, STIX_SYNERR_LBRACE, &stix->c->tok.loc, &stix->c->tok.name); return -1; } + GET_TOKEN (stix); + while (1) { - GET_TOKEN (stix); - if (is_token_ksym(stix, KSYM_DCL) || is_token_ksym(stix, KSYM_DECLARE)) { /* variable definition. #dcl or #declare */ diff --git a/stix/lib/main.c b/stix/lib/main.c index 85b0609..439eae0 100644 --- a/stix/lib/main.c +++ b/stix/lib/main.c @@ -190,7 +190,13 @@ static char* syntax_error_msg[] = "no character after $", "no valid character after #", "missing colon", - "string expected" /* string expected in place of ${1} */ + "string expected", /* string expected in place of ${1} */ + "{ expected", + "} expected", + ") expected", + ". expected", + "wrong class modifier", + "identifier expected" }; int main (int argc, char* argv[]) @@ -267,15 +273,30 @@ printf ("%p\n", a); if (stix->errnum == STIX_ESYNTAX) { stix_synerr_t synerr; + stix_bch_t bcs[1024]; /* TODO: right buffer size */ + stix_size_t bcslen, ucslen; + stix_getsynerr (stix, &synerr); - printf ("ERROR: syntax error at line %lu column %lu - %s", + + printf ("ERROR: "); + if (synerr.loc.file) + { + bcslen = STIX_COUNTOF(bcs); + ucslen = ~(stix_size_t)0; + if (stix_ucstoutf8 (synerr.loc.file, &ucslen, bcs, &bcslen) >= 0) + { + printf ("%.*s ", (int)bcslen, bcs); + } + } + + + printf ("syntax error at line %lu column %lu - %s", (unsigned long int)synerr.loc.line, (unsigned long int)synerr.loc.colm, syntax_error_msg[synerr.num]); if (synerr.tgt.len > 0) { - stix_bch_t bcs[1024]; /* TODO: right buffer size */ - stix_size_t bcslen = STIX_COUNTOF(bcs); - stix_size_t ucslen = synerr.tgt.len; + bcslen = STIX_COUNTOF(bcs); + ucslen = synerr.tgt.len; if (stix_ucstoutf8 (synerr.tgt.ptr, &ucslen, bcs, &bcslen) >= 0) { diff --git a/stix/lib/memo.txt b/stix/lib/memo.txt index a55a2dd..6efd391 100644 --- a/stix/lib/memo.txt +++ b/stix/lib/memo.txt @@ -116,7 +116,7 @@ stix stix.im #class(#byte) Association(Magnitude) { declare a, b, c. - declare(#class_instance) x. + declare(#classinst) x. declare(#class) MAX_SIZE. function(#class) initialize @@ -500,7 +500,7 @@ class Association -> revisit the Association class defined previsously. Revisiti ## class instance variable can be accessed inside the class method only. - declare(#class_instance) d, e, f + declare(#classinst) d, e, f ## All instance variables are protected by default. declare key, value. @@ -508,7 +508,7 @@ class Association -> revisit the Association class defined previsously. Revisiti ## ## declare(#class) a, b, c. ## class variables -## declare(#class_instance) a, b, c. ## class instance variables +## declare(#classinst) a, b, c. ## class instance variables ## declare(#instance) a, b, c. ## isntance variables ## declare a,b, c. ## instance variables @@ -525,9 +525,9 @@ class Association -> revisit the Association class defined previsously. Revisiti ## Casing is not used to differentiate variable kinds like global local temporary etc. ## other modifiers (EXPERIMENTAL. JUST THINKING). -## declare(#class,#public,#rw) x. x can be accessed by other classes in read-write mode. +## declare(#class #public #rw) x. x can be accessed by other classes in read-write mode. ## function(#private) xxx xxx is a private method -## function(#class,#private) xxx xxx is private class method. +## function(#class #private) xxx xxx is private class method. function(#class) initialize {