More binary operators
This commit is contained in:
@@ -18,6 +18,13 @@ pub enum BinaryOp {
|
||||
Minus,
|
||||
Multiply,
|
||||
Divide,
|
||||
Modulo,
|
||||
Equal,
|
||||
NotEqual,
|
||||
LessThan,
|
||||
GreaterThan,
|
||||
LessThanOrEqual,
|
||||
GreaterThanOrEqual,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
@@ -105,7 +105,7 @@ field_px = { "." ~ identifier }
|
||||
call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" }
|
||||
index_px = { "[" ~ expr ~ "]" }
|
||||
binary_px = { bin_op ~ expr }
|
||||
bin_op = { "+" | "-" | "*" | "/" | "%" }
|
||||
bin_op = { "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | ">" | "<=" | ">=" }
|
||||
|
||||
expr = {
|
||||
primary ~ postfix*
|
||||
|
||||
@@ -341,6 +341,14 @@ impl Postfix {
|
||||
"-" => BinaryOp::Minus,
|
||||
"*" => BinaryOp::Multiply,
|
||||
"/" => 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())
|
||||
}
|
||||
|
||||
+15
-1
@@ -1,3 +1,17 @@
|
||||
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