Skip to content

Commit

Permalink
added logical_or to diretx backend (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
themaverick authored Dec 26, 2024
1 parent 0ddc76b commit 18466a1
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 @@ -51,7 +51,7 @@
("ASSIGN_AND", r"\&="),
("BITWISE_XOR", r"\^"),
("AND", r"&&"),
("OR", r"\|\|"),
("LOGICAL_OR", r"\|\|"),
("BITWISE_OR", r"\|"),
("DOT", r"\."),
("MULTIPLY", 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 @@ -428,9 +428,9 @@ def parse_assignment(self):

def parse_logical_or(self):
left = self.parse_logical_and()
while self.current_token[0] == "OR":
while self.current_token[0] == "LOGICAL_OR":
op = self.current_token[1]
self.eat("OR")
self.eat("LOGICAL_OR")
right = self.parse_logical_and()
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 @@ -182,5 +182,16 @@ def test_bitwise_or_tokenization():
pytest.fail("bitwise_op tokenization is not implemented.")


def test_logical_or_tokenization():
code = """
bool val_0 = true;
bool val_1 = val_0 || false;
"""
try:
tokenize_code(code)
except SyntaxError:
pytest.fail("logical_or 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 @@ -257,5 +257,30 @@ def test_bitwise_ops_parsing():
pytest.fail("bitwise_op parsing not implemented.")


def test_logical_or_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 OR
bool condition1 = true; // First condition
bool condition2 = false; // Second condition
if (condition1 || condition2) {
// If one of the condition is true
output.out_color = float4(1.0, 0.0, 0.0, 1.0); // Set color to red
} else {
// If both of the conditions are 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_or_ops not implemented.")


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

0 comments on commit 18466a1

Please sign in to comment.