lang: add var keyword for variable declarations

the var keyword allows greater control over what scope a
particular variable exists in. it clarifies whether a new
variable is being defined or an existing variable is being
assigned to. it will also facilitate the implementation of
global variables.
This commit is contained in:
2025-04-15 11:02:47 +01:00
parent abebdb595a
commit e430b7b2f1
9 changed files with 190 additions and 4 deletions

View File

@@ -46,6 +46,7 @@ static struct lex_token_def keywords[] = {
LEX_TOKEN_DEF(IVY_KW_GET, "get"),
LEX_TOKEN_DEF(IVY_KW_SET, "set"),
LEX_TOKEN_DEF(IVY_KW_END, "end"),
LEX_TOKEN_DEF(IVY_KW_VAR, "var"),
};
static const size_t nr_keywords = sizeof keywords / sizeof keywords[0];
@@ -1154,6 +1155,7 @@ const char *ivy_keyword_to_string(enum ivy_keyword keyword)
ENUM_STR(IVY_KW_GET);
ENUM_STR(IVY_KW_SET);
ENUM_STR(IVY_KW_END);
ENUM_STR(IVY_KW_VAR);
default:
return "";
}