From 39b15d42071c5f0e73bb1fcd810253b0d1d0564f Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Fri, 8 May 2026 15:43:57 +0200 Subject: [PATCH] More binary op --- parser/src/ast.rs | 2 ++ parser/src/grammar.pest | 2 +- parser/src/lib.rs | 2 ++ src/codegen.rs | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/parser/src/ast.rs b/parser/src/ast.rs index 7ff1df8..dc77c0e 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -62,6 +62,8 @@ pub enum BinaryOp { GreaterThan, LessThanOrEqual, GreaterThanOrEqual, + And, + Or, } #[derive(Debug, Clone, Serialize)] diff --git a/parser/src/grammar.pest b/parser/src/grammar.pest index 7c207f5..d4b35ad 100644 --- a/parser/src/grammar.pest +++ b/parser/src/grammar.pest @@ -192,7 +192,7 @@ macro_call_px = { "!" ~ "(" ~ macro_inner_v* ~ ")" } struct_px = { "{" ~ (struct_field_decl ~ ("," ~ struct_field_decl)*)? ~ ","? ~ "}" } index_px = { "[" ~ expr ~ "]" } binary_px = { bin_op ~ expr } -bin_op = { "<=" | ">=" | "==" | "!=" | "+" | "-" | "*" | "/" | "%" | "<" | ">" } +bin_op = { "<=" | ">=" | "==" | "!=" | "&&" | "||" | "+" | "-" | "*" | "/" | "%" | "<" | ">" } struct_field_decl = { identifier ~ ":" ~ expr } prefix = { diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 636223a..2128993 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -498,6 +498,8 @@ impl From> for Postfix { ">" => BinaryOp::GreaterThan, "<=" => BinaryOp::LessThanOrEqual, ">=" => BinaryOp::GreaterThanOrEqual, + "&&" => BinaryOp::And, + "||" => BinaryOp::Or, _ => { unimplemented!("Binary operator not implemented yet: {}", op_pair.as_str()) diff --git a/src/codegen.rs b/src/codegen.rs index 6558d35..96e5bd7 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -238,6 +238,8 @@ impl GetRust for Postfix { BinaryOp::GreaterThan => ">", BinaryOp::LessThanOrEqual => "<=", BinaryOp::GreaterThanOrEqual => ">=", + BinaryOp::And => "&&", + BinaryOp::Or => "||", }; format!(" {} {}", op_str, rhs.get_rust()) }