More binary operators
This commit is contained in:
@@ -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)]
|
||||||
|
|||||||
@@ -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*
|
||||||
|
|||||||
@@ -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
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user