🐐 LTE/GTE

This commit is contained in:
2026-04-24 16:02:03 +02:00
parent 92301f3ff6
commit bdf72b2bcc
12 changed files with 88 additions and 5 deletions
+10
View File
@@ -64,6 +64,8 @@ OP_STR = {
"KEYWORD_EST": "EST", "KEYWORD_DISPAR": "DISPAR",
"KEYWORD_MINVS": "MINVS",
"KEYWORD_PLVS": "PLVS", "KEYWORD_ET": "ET", "KEYWORD_AVT": "AVT",
"KEYWORD_HAVD_PLVS": "HAVD_PLVS",
"KEYWORD_HAVD_MINVS": "HAVD_MINVS",
}
def single_num_to_int(i, m):
@@ -937,6 +939,14 @@ class BinOp(Node):
if isinstance(lv, (str, list)) or isinstance(rv, (str, list)):
raise CentvrionError("Cannot compare strings or arrays with PLVS")
return vtable, ValBool((lv or 0) > (rv or 0))
case "KEYWORD_HAVD_PLVS":
if isinstance(lv, (str, list)) or isinstance(rv, (str, list)):
raise CentvrionError("Cannot compare strings or arrays with HAVD_PLVS")
return vtable, ValBool((lv or 0) <= (rv or 0))
case "KEYWORD_HAVD_MINVS":
if isinstance(lv, (str, list)) or isinstance(rv, (str, list)):
raise CentvrionError("Cannot compare strings or arrays with HAVD_MINVS")
return vtable, ValBool((lv or 0) >= (rv or 0))
case "KEYWORD_EST":
if ((isinstance(left, ValInt) and lv == 0 and isinstance(right, ValNul)) or
(isinstance(left, ValNul) and isinstance(right, ValInt) and rv == 0)):
+2
View File
@@ -19,6 +19,8 @@ _BINOP_FN = {
"KEYWORD_DISPAR": "cent_neq",
"KEYWORD_MINVS": "cent_lt",
"KEYWORD_PLVS": "cent_gt",
"KEYWORD_HAVD_PLVS": "cent_lte",
"KEYWORD_HAVD_MINVS": "cent_gte",
"KEYWORD_ET": "cent_and",
"KEYWORD_AVT": "cent_or",
}
+22
View File
@@ -564,6 +564,28 @@ CentValue cent_gt(CentValue a, CentValue b) {
return cent_null();
}
CentValue cent_lte(CentValue a, CentValue b) {
if ((a.type == CENT_INT || a.type == CENT_FRAC || a.type == CENT_NULL) &&
(b.type == CENT_INT || b.type == CENT_FRAC || b.type == CENT_NULL)) {
long an, ad, bn, bd;
to_frac(a, &an, &ad); to_frac(b, &bn, &bd);
return cent_bool(an * bd <= bn * ad);
}
cent_type_error("'HAVD_PLVS' requires two integers");
return cent_null();
}
CentValue cent_gte(CentValue a, CentValue b) {
if ((a.type == CENT_INT || a.type == CENT_FRAC || a.type == CENT_NULL) &&
(b.type == CENT_INT || b.type == CENT_FRAC || b.type == CENT_NULL)) {
long an, ad, bn, bd;
to_frac(a, &an, &ad); to_frac(b, &bn, &bd);
return cent_bool(an * bd >= bn * ad);
}
cent_type_error("'HAVD_MINVS' requires two integers");
return cent_null();
}
CentValue cent_and(CentValue a, CentValue b) {
if (a.type != CENT_BOOL || b.type != CENT_BOOL)
cent_type_error("'ET' requires two booleans");
@@ -210,6 +210,8 @@ CentValue cent_eq (CentValue a, CentValue b); /* EST → BOOL */
CentValue cent_neq(CentValue a, CentValue b); /* DISPAR → BOOL */
CentValue cent_lt (CentValue a, CentValue b); /* MINVS → BOOL */
CentValue cent_gt (CentValue a, CentValue b); /* PLVS → BOOL */
CentValue cent_lte(CentValue a, CentValue b); /* HAVD_PLVS → BOOL */
CentValue cent_gte(CentValue a, CentValue b); /* HAVD_MINVS → BOOL */
CentValue cent_and(CentValue a, CentValue b); /* ET → BOOL */
CentValue cent_or (CentValue a, CentValue b); /* AVT → BOOL */
+2
View File
@@ -20,6 +20,8 @@ keyword_tokens = [("KEYWORD_"+i, i) for i in [
"FAC",
"FALSITAS",
"FVNCTIO",
"HAVD_MINVS",
"HAVD_PLVS",
"INVOCA",
"IN",
"MINVE",
+4 -1
View File
@@ -115,7 +115,8 @@ class Parser():
precedence=[
('left', ["KEYWORD_AVT"]),
('left', ["KEYWORD_ET"]),
('left', ["KEYWORD_PLVS", "KEYWORD_MINVS", "KEYWORD_EST", "KEYWORD_DISPAR"]),
('left', ["KEYWORD_PLVS", "KEYWORD_MINVS", "KEYWORD_EST", "KEYWORD_DISPAR",
"KEYWORD_HAVD_PLVS", "KEYWORD_HAVD_MINVS"]),
('left', ["SYMBOL_AMPERSAND", "SYMBOL_AT", "SYMBOL_PLUS", "SYMBOL_MINUS"]),
('left', ["SYMBOL_TIMES", "SYMBOL_DIVIDE", "KEYWORD_RELIQVVM"]),
('right', ["UMINUS", "UNOT"]),
@@ -334,6 +335,8 @@ class Parser():
@self.pg.production('expression : expression KEYWORD_DISPAR expression')
@self.pg.production('expression : expression KEYWORD_MINVS expression')
@self.pg.production('expression : expression KEYWORD_PLVS expression')
@self.pg.production('expression : expression KEYWORD_HAVD_PLVS expression')
@self.pg.production('expression : expression KEYWORD_HAVD_MINVS expression')
@self.pg.production('expression : expression KEYWORD_ET expression')
@self.pg.production('expression : expression KEYWORD_AVT expression')
def binop(tokens):