🐐 Fixing latin
This commit is contained in:
@@ -935,7 +935,7 @@ class SiStatement(Node):
|
||||
result = f"SI {self.test.print()} TVNC {{\n{body}\n}}"
|
||||
if self.else_part:
|
||||
else_body = "\n".join(s.print() for s in self.else_part)
|
||||
result += f" ALVID {{\n{else_body}\n}}"
|
||||
result += f" ALIVD {{\n{else_body}\n}}"
|
||||
return result
|
||||
|
||||
def _eval(self, vtable):
|
||||
@@ -972,7 +972,7 @@ class DumStatement(Node):
|
||||
|
||||
def print(self):
|
||||
body = "\n".join(s.print() for s in self.statements)
|
||||
return f"DVM {self.test.print()} FACE {{\n{body}\n}}"
|
||||
return f"DVM {self.test.print()} FAC {{\n{body}\n}}"
|
||||
|
||||
def _eval(self, vtable):
|
||||
last_val = ValNul()
|
||||
@@ -1016,7 +1016,7 @@ class PerStatement(Node):
|
||||
|
||||
def print(self):
|
||||
body = "\n".join(s.print() for s in self.statements)
|
||||
return f"PER {self.variable_name.print()} IN {self.data_list.print()} FACE {{\n{body}\n}}"
|
||||
return f"PER {self.variable_name.print()} IN {self.data_list.print()} FAC {{\n{body}\n}}"
|
||||
|
||||
def _eval(self, vtable):
|
||||
vtable, array = self.data_list.eval(vtable)
|
||||
@@ -1158,7 +1158,7 @@ class BuiltIn(Node):
|
||||
raise CentvrionError(f"Invalid numeral input: {raw!r}")
|
||||
case "AVDI":
|
||||
return vtable, ValStr(input())
|
||||
case "DICE":
|
||||
case "DIC":
|
||||
print_string = ' '.join(
|
||||
make_string(i, magnvm, svbnvlla) for i in params
|
||||
)
|
||||
@@ -1167,23 +1167,23 @@ class BuiltIn(Node):
|
||||
case "ERVMPE":
|
||||
vtable["#break"] = True
|
||||
return vtable, ValNul()
|
||||
case "FORTIS_NVMERVS":
|
||||
case "FORTVITVS_NVMERVS":
|
||||
if "FORS" not in vtable["#modules"]:
|
||||
raise CentvrionError("Cannot use 'FORTIS_NVMERVS' without module 'FORS'")
|
||||
raise CentvrionError("Cannot use 'FORTVITVS_NVMERVS' without module 'FORS'")
|
||||
a, b = params[0].value(), params[1].value()
|
||||
if not isinstance(a, int) or not isinstance(b, int):
|
||||
raise CentvrionError("FORTIS_NVMERVS requires two numbers")
|
||||
raise CentvrionError("FORTVITVS_NVMERVS requires two numbers")
|
||||
if a > b:
|
||||
raise CentvrionError(f"FORTIS_NVMERVS: first argument ({a}) must be ≤ second ({b})")
|
||||
raise CentvrionError(f"FORTVITVS_NVMERVS: first argument ({a}) must be ≤ second ({b})")
|
||||
return vtable, ValInt(random.randint(a, b))
|
||||
case "FORTIS_ELECTIONIS":
|
||||
case "FORTVITA_ELECTIO":
|
||||
if "FORS" not in vtable["#modules"]:
|
||||
raise CentvrionError("Cannot use 'FORTIS_ELECTIONIS' without module 'FORS'")
|
||||
raise CentvrionError("Cannot use 'FORTVITA_ELECTIO' without module 'FORS'")
|
||||
if not isinstance(params[0], ValList):
|
||||
raise CentvrionError("FORTIS_ELECTIONIS requires an array")
|
||||
raise CentvrionError("FORTVITA_ELECTIO requires an array")
|
||||
lst = params[0].value()
|
||||
if len(lst) == 0:
|
||||
raise CentvrionError("FORTIS_ELECTIONIS: cannot select from an empty array")
|
||||
raise CentvrionError("FORTVITA_ELECTIO: cannot select from an empty array")
|
||||
return vtable, lst[random.randint(0, len(lst) - 1)]
|
||||
case "SEMEN":
|
||||
if "FORS" not in vtable["#modules"]:
|
||||
@@ -1222,7 +1222,7 @@ class BuiltIn(Node):
|
||||
raise CentvrionError("CLAVES requires a dict")
|
||||
keys = [ValStr(k) if isinstance(k, str) else ValInt(k) for k in params[0].value().keys()]
|
||||
return vtable, ValList(keys)
|
||||
case "EVERRO":
|
||||
case "EVERRE":
|
||||
print("\033[2J\033[H", end="", flush=True)
|
||||
return vtable, ValNul()
|
||||
case "ORDINA":
|
||||
|
||||
@@ -188,12 +188,12 @@ def _emit_builtin(node, ctx):
|
||||
tmp = ctx.fresh_tmp()
|
||||
|
||||
match node.builtin:
|
||||
case "DICE":
|
||||
case "DIC":
|
||||
if not param_vars:
|
||||
lines.append('cent_dice(cent_str(""));')
|
||||
lines.append('cent_dic(cent_str(""));')
|
||||
lines.append(f'CentValue {tmp} = cent_str("");')
|
||||
elif len(param_vars) == 1:
|
||||
lines.append(f"cent_dice({param_vars[0]});")
|
||||
lines.append(f"cent_dic({param_vars[0]});")
|
||||
lines.append(f"CentValue {tmp} = {param_vars[0]};")
|
||||
else:
|
||||
acc = param_vars[0]
|
||||
@@ -203,7 +203,7 @@ def _emit_builtin(node, ctx):
|
||||
lines.append(f'CentValue {space_tmp} = cent_concat({acc}, cent_str(" "));')
|
||||
lines.append(f"CentValue {joined_tmp} = cent_concat({space_tmp}, {pv});")
|
||||
acc = joined_tmp
|
||||
lines.append(f"cent_dice({acc});")
|
||||
lines.append(f"cent_dic({acc});")
|
||||
lines.append(f"CentValue {tmp} = {acc};")
|
||||
|
||||
case "AVDI":
|
||||
@@ -215,19 +215,19 @@ def _emit_builtin(node, ctx):
|
||||
case "LONGITVDO":
|
||||
lines.append(f"CentValue {tmp} = cent_longitudo({param_vars[0]});")
|
||||
|
||||
case "FORTIS_NVMERVS":
|
||||
case "FORTVITVS_NVMERVS":
|
||||
if not ctx.has_module("FORS"):
|
||||
lines.append('cent_runtime_error("FORS module required for FORTIS_NVMERVS");')
|
||||
lines.append('cent_runtime_error("FORS module required for FORTVITVS_NVMERVS");')
|
||||
lines.append(f"CentValue {tmp} = cent_null();")
|
||||
else:
|
||||
lines.append(f"CentValue {tmp} = cent_fortis_numerus({param_vars[0]}, {param_vars[1]});")
|
||||
lines.append(f"CentValue {tmp} = cent_fortuitus_numerus({param_vars[0]}, {param_vars[1]});")
|
||||
|
||||
case "FORTIS_ELECTIONIS":
|
||||
case "FORTVITA_ELECTIO":
|
||||
if not ctx.has_module("FORS"):
|
||||
lines.append('cent_runtime_error("FORS module required for FORTIS_ELECTIONIS");')
|
||||
lines.append('cent_runtime_error("FORS module required for FORTVITA_ELECTIO");')
|
||||
lines.append(f"CentValue {tmp} = cent_null();")
|
||||
else:
|
||||
lines.append(f"CentValue {tmp} = cent_fortis_electionis({param_vars[0]});")
|
||||
lines.append(f"CentValue {tmp} = cent_fortuita_electionis({param_vars[0]});")
|
||||
|
||||
case "DECIMATIO":
|
||||
if not ctx.has_module("FORS"):
|
||||
@@ -263,8 +263,8 @@ def _emit_builtin(node, ctx):
|
||||
case "ORDINA":
|
||||
lines.append(f"CentValue {tmp} = cent_ordina({param_vars[0]});")
|
||||
|
||||
case "EVERRO":
|
||||
lines.append("cent_everro();")
|
||||
case "EVERRE":
|
||||
lines.append("cent_everre();")
|
||||
lines.append(f"CentValue {tmp} = cent_null();")
|
||||
|
||||
case "TYPVS":
|
||||
|
||||
@@ -521,13 +521,13 @@ CentValue cent_or(CentValue a, CentValue b) {
|
||||
/* Builtin functions */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
void cent_dice(CentValue v) {
|
||||
void cent_dic(CentValue v) {
|
||||
char *s = cent_make_string(v);
|
||||
fputs(s, stdout);
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
void cent_everro(void) {
|
||||
void cent_everre(void) {
|
||||
fputs("\033[2J\033[H", stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
@@ -622,20 +622,20 @@ void cent_adivnge(CentValue path, CentValue content) {
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
CentValue cent_fortis_numerus(CentValue lo, CentValue hi) {
|
||||
CentValue cent_fortuitus_numerus(CentValue lo, CentValue hi) {
|
||||
if (lo.type != CENT_INT || hi.type != CENT_INT)
|
||||
cent_type_error("'FORTIS_NVMERVS' requires two integers");
|
||||
cent_type_error("'FORTVITVS_NVMERVS' requires two integers");
|
||||
long range = hi.ival - lo.ival + 1;
|
||||
if (range <= 0)
|
||||
cent_runtime_error("'FORTIS_NVMERVS' requires lo <= hi");
|
||||
cent_runtime_error("'FORTVITVS_NVMERVS' requires lo <= hi");
|
||||
return cent_int(lo.ival + rand() % range);
|
||||
}
|
||||
|
||||
CentValue cent_fortis_electionis(CentValue lst) {
|
||||
CentValue cent_fortuita_electionis(CentValue lst) {
|
||||
if (lst.type != CENT_LIST)
|
||||
cent_type_error("'FORTIS_ELECTIONIS' requires a list");
|
||||
cent_type_error("'FORTVITA_ELECTIO' requires a list");
|
||||
if (lst.lval.len == 0)
|
||||
cent_runtime_error("'FORTIS_ELECTIONIS' requires a non-empty list");
|
||||
cent_runtime_error("'FORTVITA_ELECTIO' requires a non-empty list");
|
||||
return lst.lval.items[rand() % lst.lval.len];
|
||||
}
|
||||
|
||||
|
||||
@@ -216,15 +216,15 @@ CentValue cent_or (CentValue a, CentValue b); /* AVT → BOOL */
|
||||
/* Builtin functions */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
void cent_dice(CentValue v); /* DICE */
|
||||
void cent_dic(CentValue v); /* DIC */
|
||||
CentValue cent_avdi(void); /* AVDI */
|
||||
CentValue cent_avdi_numerus(void); /* AVDI_NVMERVS */
|
||||
CentValue cent_longitudo(CentValue v); /* LONGITVDO */
|
||||
CentValue cent_fortis_numerus(CentValue lo, CentValue hi); /* FORTIS_NVMERVS */
|
||||
CentValue cent_fortis_electionis(CentValue lst); /* FORTIS_ELECTIONIS */
|
||||
CentValue cent_fortuitus_numerus(CentValue lo, CentValue hi); /* FORTVITVS_NVMERVS */
|
||||
CentValue cent_fortuita_electionis(CentValue lst); /* FORTVITA_ELECTIO */
|
||||
CentValue cent_decimatio(CentValue lst); /* DECIMATIO */
|
||||
void cent_semen(CentValue seed); /* SEMEN */
|
||||
void cent_everro(void); /* EVERRO */
|
||||
void cent_everre(void); /* EVERRE */
|
||||
CentValue cent_senatus(CentValue *args, int n); /* SENATVS */
|
||||
CentValue cent_typvs(CentValue v); /* TYPVS */
|
||||
void cent_dormi(CentValue n); /* DORMI */
|
||||
|
||||
@@ -4,7 +4,7 @@ valid_characters = '|'.join(list("abcdefghiklmnopqrstvxyz_"))
|
||||
|
||||
keyword_tokens = [("KEYWORD_"+i, i) for i in [
|
||||
"AETERNVM",
|
||||
"ALVID",
|
||||
"ALIVD",
|
||||
"AVGE",
|
||||
"CAPE",
|
||||
"AVT",
|
||||
@@ -17,7 +17,7 @@ keyword_tokens = [("KEYWORD_"+i, i) for i in [
|
||||
"ERVMPE",
|
||||
"EST",
|
||||
"ET",
|
||||
"FACE",
|
||||
"FAC",
|
||||
"FALSITAS",
|
||||
"FVNCTIO",
|
||||
"INVOCA",
|
||||
@@ -45,11 +45,11 @@ builtin_tokens = [("BUILTIN", i) for i in [
|
||||
"AVDI",
|
||||
"CLAVES",
|
||||
"DECIMATIO",
|
||||
"DICE",
|
||||
"DIC",
|
||||
"DORMI",
|
||||
"EVERRO",
|
||||
"FORTIS_NVMERVS",
|
||||
"FORTIS_ELECTIONIS",
|
||||
"EVERRE",
|
||||
"FORTVITVS_NVMERVS",
|
||||
"FORTVITA_ELECTIO",
|
||||
"LONGITVDO",
|
||||
"ORDINA",
|
||||
"SEMEN",
|
||||
|
||||
@@ -183,24 +183,24 @@ class Parser():
|
||||
else:
|
||||
return ast_nodes.SiStatement(tokens[1], tokens[4], None)
|
||||
|
||||
@self.pg.production('aluid_statement : KEYWORD_ALVID si_statement')
|
||||
@self.pg.production('aluid_statement : KEYWORD_ALIVD si_statement')
|
||||
def aluid_si(tokens):
|
||||
return [tokens[1]]
|
||||
|
||||
@self.pg.production('aluid_statement : KEYWORD_ALVID SYMBOL_LCURL statements SYMBOL_RCURL')
|
||||
@self.pg.production('aluid_statement : KEYWORD_ALIVD SYMBOL_LCURL statements SYMBOL_RCURL')
|
||||
def aluid(tokens):
|
||||
return tokens[2]
|
||||
|
||||
@self.pg.production('dum_statement : KEYWORD_DVM expression KEYWORD_FACE SYMBOL_LCURL statements SYMBOL_RCURL')
|
||||
@self.pg.production('dum_statement : KEYWORD_DVM expression KEYWORD_FAC SYMBOL_LCURL statements SYMBOL_RCURL')
|
||||
def dum(tokens):
|
||||
return ast_nodes.DumStatement(tokens[1], tokens[4])
|
||||
|
||||
# AETERNVM is sugar for `DVM FALSITAS` — same AST, no observable difference.
|
||||
@self.pg.production('dum_statement : KEYWORD_AETERNVM KEYWORD_FACE SYMBOL_LCURL statements SYMBOL_RCURL')
|
||||
@self.pg.production('dum_statement : KEYWORD_AETERNVM KEYWORD_FAC SYMBOL_LCURL statements SYMBOL_RCURL')
|
||||
def aeternvm(tokens):
|
||||
return ast_nodes.DumStatement(ast_nodes.Bool(False), tokens[3])
|
||||
|
||||
@self.pg.production('per_statement : KEYWORD_PER id KEYWORD_IN expression KEYWORD_FACE SYMBOL_LCURL statements SYMBOL_RCURL')
|
||||
@self.pg.production('per_statement : KEYWORD_PER id KEYWORD_IN expression KEYWORD_FAC SYMBOL_LCURL statements SYMBOL_RCURL')
|
||||
def per(tokens):
|
||||
return ast_nodes.PerStatement(tokens[3], tokens[1], tokens[6])
|
||||
|
||||
@@ -208,7 +208,7 @@ class Parser():
|
||||
def tempta(tokens):
|
||||
return ast_nodes.TemptaStatement(tokens[2], tokens[5], tokens[7])
|
||||
|
||||
@self.pg.production('donicum_statement : KEYWORD_DONICVM id KEYWORD_VT expression KEYWORD_VSQVE expression KEYWORD_FACE SYMBOL_LCURL statements SYMBOL_RCURL')
|
||||
@self.pg.production('donicum_statement : KEYWORD_DONICVM id KEYWORD_VT expression KEYWORD_VSQVE expression KEYWORD_FAC SYMBOL_LCURL statements SYMBOL_RCURL')
|
||||
def donicum(tokens):
|
||||
range_array = ast_nodes.DataRangeArray(tokens[3], tokens[5])
|
||||
return ast_nodes.PerStatement(range_array, tokens[1], tokens[8])
|
||||
|
||||
Reference in New Issue
Block a user