Repository: CrossGL/crosstl

Issue:
BITWISE_AND : &
<!-- BOT_STATE: {} -->

Discussion:
@anshikavashistha: @samthakur587 Please assign it to me .@Tanzeem-Pasha: Please assign me this @AtulC137: hey hii ... i would to work on this task if possible !@SiddharthKarmokar: Please assign this to me!@AishaRuqshan: I would appreciate the opportunity to take on this task. Please consider assigning it to me, as I am confident in my ability to handle it effectively.@tiashamaitra: BITWISE_AND : & #178 pls assign me @samthakur587 @thepriyanshpal: Hi @NripeshN,

I would like to work on this issue and contribute to adding support for the `BITWISE_AND` operator in the DirectX backend. Could you please assign it to me?

Thank you!
@NripeshN: To assign issues to yourself please read this documentation: https://github.com/CrossGL/crosstl/blob/main/CONTRIBUTING.md#-assigning-or-creating-issues@SiddharthKarmokar: @CrossGL-issue-bot assign me@CrossGL-issue-bot: Thank you for taking on this issue! If you have any questions or need assistance, feel free to ask.@weeby121: @CrossGL-issue-bot assign me@CrossGL-issue-bot: The issue you are trying to assign to yourself is already assigned.@vaishnavikotwal04: @samthakur587  Please assign it to me .

Solution patch:
diff --git a/crosstl/backend/DirectX/DirectxLexer.py b/crosstl/backend/DirectX/DirectxLexer.py
index a85cc9de..e6c4c28a 100644
--- a/crosstl/backend/DirectX/DirectxLexer.py
+++ b/crosstl/backend/DirectX/DirectxLexer.py
@@ -103,6 +103,7 @@
         ("DEFAULT", r"\bdefault\b"),
         ("BREAK", r"\bbreak\b"),
         ("MOD", r"%"),
+        ("BITWISE_AND", r"&"),
     ]
 )
 
diff --git a/crosstl/backend/DirectX/DirectxParser.py b/crosstl/backend/DirectX/DirectxParser.py
index 5c5ff80b..1c469521 100644
--- a/crosstl/backend/DirectX/DirectxParser.py
+++ b/crosstl/backend/DirectX/DirectxParser.py
@@ -258,6 +258,7 @@ def parse_variable_declaration_or_assignment(self):
                     "SHIFT_LEFT",
                     "SHIFT_RIGHT",
                     "BITWISE_OR",
+                    "BITWISE_AND",
                     "BITWISE_XOR",
                 ]:
                     # Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
@@ -279,6 +280,7 @@ def parse_variable_declaration_or_assignment(self):
                 "SHIFT_LEFT",
                 "SHIFT_RIGHT",
                 "BITWISE_OR",
+                "BITWISE_AND",
                 "BITWISE_XOR",
             ]:
                 # Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
@@ -303,6 +305,7 @@ def parse_variable_declaration_or_assignment(self):
                     "SHIFT_LEFT",
                     "SHIFT_RIGHT",
                     "BITWISE_OR",
+                    "BITWISE_AND",
                     "BITWISE_XOR",
                 ]:
                     op = self.current_token[1]
@@ -435,6 +438,7 @@ def parse_assignment(self):
             "SHIFT_LEFT",
             "SHIFT_RIGHT",
             "BITWISE_OR",
+            "BITWISE_AND",
             "BITWISE_XOR",
         ]:
             op = self.current_token[1]


Test patch:
diff --git a/tests/test_backend/test_directx/test_codegen.py b/tests/test_backend/test_directx/test_codegen.py
index 505a08f0..e82bc25c 100644
--- a/tests/test_backend/test_directx/test_codegen.py
+++ b/tests/test_backend/test_directx/test_codegen.py
@@ -575,6 +575,33 @@ def test_switch_case_codegen():
         pytest.fail("Switch-case parsing or code generation not implemented.")
 
 
+def test_bitwise_and_ops_codgen():
+    code = """
+        PSOutput PSMain(PSInput input) {
+            PSOutput output;
+            output.out_color = float4(0.0, 0.0, 0.0, 1.0);
+            uint val = 0x01;
+            if (val & 0x02) {
+                // Test case for bitwise AND
+            }
+            uint filterA = 0b0001; // First filter
+            uint filterB = 0b1000; // Second filter
+
+            // Merge both filters
+            uint combinedFilter = filterA & filterB; // combinedFilter becomes 0b1001
+            return output;
+        }
+        
+        """
+    try:
+        tokens = tokenize_code(code)
+        ast = parse_code(tokens)
+        generated_code = generate_code(ast)
+        print(generated_code)
+    except SyntaxError:
+        pytest.fail("bitwise_and_op codegen not implemented.")
+
+
 def test_double_dtype_codegen():
     code = """
             PSOutput PSMain(PSInput input) {
diff --git a/tests/test_backend/test_directx/test_lexer.py b/tests/test_backend/test_directx/test_lexer.py
index 85424921..661ec9dd 100644
--- a/tests/test_backend/test_directx/test_lexer.py
+++ b/tests/test_backend/test_directx/test_lexer.py
@@ -228,6 +228,17 @@ def test_switch_case_tokenization():
         pytest.fail("switch-case tokenization not implemented.")
 
 
+def test_bitwise_and_tokenization():
+    code = """
+        uint val = 0x01;
+        val = val & 0x02;
+    """
+    try:
+        tokenize_code(code)
+    except SyntaxError:
+        pytest.fail("bitwise_and_op tokenization is not implemented.")
+
+
 def test_double_dtype_tokenization():
     code = """
             PSOutput PSMain(PSInput input) {
diff --git a/tests/test_backend/test_directx/test_parser.py b/tests/test_backend/test_directx/test_parser.py
index 1128734c..abad0b42 100644
--- a/tests/test_backend/test_directx/test_parser.py
+++ b/tests/test_backend/test_directx/test_parser.py
@@ -332,6 +332,30 @@ def test_switch_case_parsing():
         pytest.fail("switch-case parsing not implemented.")
 
 
+def test_bitwise_and_parsing():
+    code = """
+        PSOutput PSMain(PSInput input) {
+            PSOutput output;
+            output.out_color = float4(0.0, 0.0, 0.0, 1.0);
+            uint val = 0x01;
+            if (val & 0x02) {
+                // Test case for bitwise AND
+            }
+            uint filterA = 0b0001; // First filter
+            uint filterB = 0b1000; // Second filter
+
+            // Merge both filters
+            uint combinedFilter = filterA & filterB; // combinedFilter becomes 0b1001
+            return output;
+        }
+    """
+    try:
+        tokens = tokenize_code(code)
+        parse_code(tokens)
+    except SyntaxError:
+        pytest.fail("bitwise_and_op parsing not implemented.")
+
+
 def test_double_dtype_parsing():
     code = """
             PSOutput PSMain(PSInput input) {