Skip to content

Commit

Permalink
Support for LOGICAL AND operator in DirectX backend (#232)
Browse files Browse the repository at this point in the history
Signed-off-by: Jyotin Goel <[email protected]>
  • Loading branch information
gjyotin305 authored Dec 26, 2024
1 parent c147858 commit 17e4ba0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crosstl/backend/DirectX/DirectxLexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
("ASSIGN_OR", r"\|="),
("ASSIGN_AND", r"\&="),
("BITWISE_XOR", r"\^"),
("AND", r"&&"),
("LOGICAL_AND", r"&&"),
("LOGICAL_OR", r"\|\|"),
("BITWISE_OR", r"\|"),
("DOT", r"\."),
Expand Down
4 changes: 2 additions & 2 deletions crosstl/backend/DirectX/DirectxParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,9 @@ def parse_logical_or(self):

def parse_logical_and(self):
left = self.parse_equality()
while self.current_token[0] == "AND":
while self.current_token[0] == "LOGICAL_AND":
op = self.current_token[1]
self.eat("AND")
self.eat("LOGICAL_AND")
right = self.parse_equality()
left = BinaryOpNode(left, op, right)
return left
Expand Down
11 changes: 11 additions & 0 deletions tests/test_backend/test_directx/test_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,16 @@ def test_logical_or_tokenization():
pytest.fail("logical_or tokenization is not implemented.")


def test_logical_and_tokenization():
code = """
bool val_0 = true;
bool val_1 = val_0 && false;
"""
try:
tokenize_code(code)
except SyntaxError:
pytest.fail("logical_and tokenization is not implemented.")


if __name__ == "__main__":
pytest.main()
25 changes: 25 additions & 0 deletions tests/test_backend/test_directx/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,30 @@ def test_logical_or_ops_parsing():
pytest.fail("logical_or_ops not implemented.")


def test_logical_and_ops_parsing():
code = """
PSOutput PSMain(PSInput input) {
PSOutput output;
output.out_color = float4(0.0, 0.0, 0.0, 1.0);
// Test case for logical AND
bool condition1 = true; // First condition
bool condition2 = false; // Second condition
if (condition1 && condition2) {
// both the condition is true
output.out_color = float4(1.0, 0.0, 0.0, 1.0); // Set color to red
} else {
// any one of the condition is false
output.out_color = float4(0.0, 1.0, 0.0, 1.0); // Set color to green
}
return output;
}
"""
try:
tokens = tokenize_code(code)
parse_code(tokens)
except SyntaxError:
pytest.fail("logical_and_ops not implemented.")


if __name__ == "__main__":
pytest.main()

0 comments on commit 17e4ba0

Please sign in to comment.