More binary operators

This commit is contained in:
2026-04-14 05:07:45 +02:00
parent 7b8010abbb
commit b2fa1e24e1
4 changed files with 31 additions and 2 deletions
+7
View File
@@ -18,6 +18,13 @@ pub enum BinaryOp {
Minus, Minus,
Multiply, Multiply,
Divide, Divide,
Modulo,
Equal,
NotEqual,
LessThan,
GreaterThan,
LessThanOrEqual,
GreaterThanOrEqual,
} }
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
+1 -1
View File
@@ -105,7 +105,7 @@ field_px = { "." ~ identifier }
call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" } call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" }
index_px = { "[" ~ expr ~ "]" } index_px = { "[" ~ expr ~ "]" }
binary_px = { bin_op ~ expr } binary_px = { bin_op ~ expr }
bin_op = { "+" | "-" | "*" | "/" | "%" } bin_op = { "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | ">" | "<=" | ">=" }
expr = { expr = {
primary ~ postfix* primary ~ postfix*
+8
View File
@@ -341,6 +341,14 @@ impl Postfix {
"-" => BinaryOp::Minus, "-" => BinaryOp::Minus,
"*" => BinaryOp::Multiply, "*" => BinaryOp::Multiply,
"/" => BinaryOp::Divide, "/" => BinaryOp::Divide,
"%" => BinaryOp::Modulo,
"==" => BinaryOp::Equal,
"!=" => BinaryOp::NotEqual,
"<" => BinaryOp::LessThan,
">" => BinaryOp::GreaterThan,
"<=" => BinaryOp::LessThanOrEqual,
">=" => BinaryOp::GreaterThanOrEqual,
_ => { _ => {
unimplemented!("Binary operator not implemented yet: {}", op_pair.as_str()) unimplemented!("Binary operator not implemented yet: {}", op_pair.as_str())
} }
+15 -1
View File
@@ -1,3 +1,17 @@
function add(a: int, b: int): int { function add(a: int, b: int): int {
itm.a + itm.b(); let sum = 0;
for (let i = 0; i < 10; i = i + 1) {
if (i == 5) {
continue;
}
sum = sum + i;
}
if (sum > 20) {
return sum;
} else {
return 0;
}
} }