X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Foberon.c;h=07c83c28643623df555292ca429fa5eba776ae9d;hb=0570527a2279ee6bd14b4c08e653b6d68369475a;hp=0bbeec188b3d5b4e7fafe506285a9d096cb809b7;hpb=1233fb1d5d8f67a8f5e970386c1c4cbb6691ec04;p=dsw-obn.git diff --git a/src/oberon.c b/src/oberon.c index 0bbeec1..07c83c2 100644 --- a/src/oberon.c +++ b/src/oberon.c @@ -356,23 +356,20 @@ oberon_init_scaner(oberon_context_t * ctx, const char * code) static void oberon_read_ident(oberon_context_t * ctx) { - int len = 0; - int i = ctx -> code_index; + int start = ctx -> code_index; - int c = ctx -> code[i]; - while(isalnum(c)) + oberon_get_char(ctx); + while(isalnum(ctx -> c) || ctx -> c == '_') { - i += 1; - len += 1; - c = ctx -> code[i]; + oberon_get_char(ctx); } - char * ident = GC_MALLOC(len + 1); - memcpy(ident, &ctx->code[ctx->code_index], len); - ident[len] = 0; + int end = ctx -> code_index; + + char * ident = GC_MALLOC(end - start + 1); + memcpy(ident, &ctx -> code[start], end - start); + ident[end - start] = 0; - ctx -> code_index = i; - ctx -> c = ctx -> code[i]; ctx -> string = ident; ctx -> token = IDENT; @@ -738,7 +735,7 @@ static void oberon_read_string(oberon_context_t * ctx) char * string = GC_MALLOC(end - start + 1); strncpy(string, &ctx -> code[start], end - start); - string[end] = 0; + string[end - start] = 0; ctx -> token = STRING; ctx -> string = string; @@ -893,7 +890,7 @@ oberon_read_token(oberon_context_t * ctx) oberon_skip_space(ctx); int c = ctx -> c; - if(isalpha(c)) + if(isalpha(c) || c == '_') { oberon_read_ident(ctx); } @@ -4493,6 +4490,9 @@ register_default_types(oberon_context_t * ctx) ctx -> system_byte_type = oberon_new_type_ptr(OBERON_TYPE_SYSTEM_BYTE); oberon_generator_init_type(ctx, ctx -> system_byte_type); + ctx -> system_ptr_type = oberon_new_type_ptr(OBERON_TYPE_SYSTEM_PTR); + oberon_generator_init_type(ctx, ctx -> system_ptr_type); + /* LONG / SHORT support */ ctx -> byte_type -> shorter = NULL; ctx -> byte_type -> longer = ctx -> shortint_type; @@ -4621,6 +4621,7 @@ oberon_create_context(ModuleImportCallback import_module) /* Types */ oberon_new_intrinsic_type(ctx, "BYTE", ctx -> system_byte_type); + oberon_new_intrinsic_type(ctx, "PTR", ctx -> system_ptr_type); oberon_end_intrinsic_module(ctx, ctx -> system_module);