bydgoszcz

simple, fast and efficient programming language
git clone git://git.kocotian.pl/bydgoszczscript.git
Log | Files | Refs | README | LICENSE

commit 57a9b6f9b32bdf27d4b221b4ef9e4f51b5fa1c92
parent 43528561c894be7fbead20e12b17a7d09b068053
Author: kocotian <kocotian@kocotian.pl>
Date:   Fri, 28 May 2021 12:46:18 +0200

Named structs (organizacje)

Diffstat:
Mcompile.c | 17++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/compile.c b/compile.c @@ -71,12 +71,22 @@ static void g_struct(File *f, TypeString *str) { Token *t; - String name; + String name, fname; TypeString type; *str->data = 0; strncat(str->data, "struct", MAX_TYPESIZE); t = enextToken(f, TokenNULL); + if (t->type == TokenIdentifier) { + name = t->c; + strncat(str->data, " ", MAX_TYPESIZE); + ++(str->len); + str->len += UMIN(strlen(str->data) + name.len, MAX_TYPESIZE); + strncat(str->data, name.data, + UMIN(name.len, MAX_TYPESIZE - str->len)); + str->data[UMIN(str->len, MAX_TYPESIZE)] = 0; + t = enextToken(f, TokenNULL); + } if (t->type == TokenColon) { strncat(str->data, " {\n", MAX_TYPESIZE); while ((t = enextToken(f, TokenIdentifier))) { @@ -84,7 +94,7 @@ g_struct(File *f, TypeString *str) strncat(str->data, "}", MAX_TYPESIZE); break; } else { - name = t->c; + fname = t->c; while ((t = enextToken(f, TokenNULL))) { if (t->type == TokenIdentifier) { if (!Strccmp(t->c, "przechowuje")) { @@ -96,7 +106,7 @@ g_struct(File *f, TypeString *str) snprintf((char *)(str->data + strlen(str->data)), MAX_TYPESIZE - strlen(str->data), "%.*s %.*s;\n", - Strevalf(type), Strevalf(name)); + Strevalf(type), Strevalf(fname)); break; } else { errwarn(*f, 1, "unexpected token (expected identifier or semicolon)"); @@ -104,6 +114,7 @@ g_struct(File *f, TypeString *str) } } } + } else if (t->type == TokenSemicolon) { } else { errwarn(*f, 1, "unexpected token (expected colon)"); }