From c29aa13d69c21bd1b0dbc4fa4eea6eda3ef543bf Mon Sep 17 00:00:00 2001 From: Marvin Schlegel Date: Thu, 9 May 2024 00:09:08 +0200 Subject: [PATCH] parser add and, or, xor --- Test/TestParser.hs | 14 +++++++++++++- src/Parser/JavaParser.y | 7 +++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Test/TestParser.hs b/Test/TestParser.hs index a3ba800..5e8eec5 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -123,6 +123,15 @@ testExpressionEqual = TestCase $ testExpressionNotEqual = TestCase $ assertEqual "expect comparison equal" (BinaryOperation CompareNotEqual (Reference "bar") (IntegerLiteral 3)) $ parseExpression [IDENTIFIER "bar",NOTEQUAL,INTEGERLITERAL 3] +testExpressionAnd = TestCase $ + assertEqual "expect and expression" (BinaryOperation And (Reference "bar") (Reference "baz")) $ + parseExpression [IDENTIFIER "bar",AND,IDENTIFIER "baz"] +testExpressionXor = TestCase $ + assertEqual "expect xor expression" (BinaryOperation BitwiseXor (Reference "bar") (Reference "baz")) $ + parseExpression [IDENTIFIER "bar",XOR,IDENTIFIER "baz"] +testExpressionOr = TestCase $ + assertEqual "expect or expression" (BinaryOperation Or (Reference "bar") (Reference "baz")) $ + parseExpression [IDENTIFIER "bar",OR,IDENTIFIER "baz"] tests = TestList [ @@ -157,5 +166,8 @@ tests = TestList [ testExpressionLessThanEqual, testExpressionGreaterThanOrEqual, testExpressionEqual, - testExpressionNotEqual + testExpressionNotEqual, + testExpressionAnd, + testExpressionXor, + testExpressionOr ] \ No newline at end of file diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index 9ba26bc..68be06c 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -44,7 +44,6 @@ import Parser.Lexer JNULL { NULLLITERAL } BOOLLITERAL { BOOLLITERAL $$ } DIV { DIV } - LOGICALOR { OR } NOTEQUAL { NOTEQUAL } INSTANCEOF { INSTANCEOF } ANDEQUAL { ANDEQUAL } @@ -310,7 +309,7 @@ postfixexpression : primary { $1 } primary : primarynonewarray { $1 } inclusiveorexpression : exclusiveorexpression { $1 } - -- | inclusiveorexpression OR exclusiveorexpression { } + | inclusiveorexpression OR exclusiveorexpression { BinaryOperation Or $1 $3 } primarynonewarray : literal { $1 } -- | THIS { } @@ -325,7 +324,7 @@ unaryexpressionnotplusminus : postfixexpression { $1 } -- | castexpression{ } exclusiveorexpression : andexpression { $1 } - -- | exclusiveorexpression XOR andexpression { } + | exclusiveorexpression XOR andexpression { BinaryOperation BitwiseXor $1 $3 } literal : INTLITERAL { IntegerLiteral $1 } | BOOLLITERAL { BooleanLiteral $1 } @@ -336,7 +335,7 @@ castexpression : LBRACE primitivetype RBRACE unaryexpression { } | LBRACE expression RBRACE unaryexpressionnotplusminus{ } andexpression : equalityexpression { $1 } - -- | andexpression AND equalityexpression { } + | andexpression AND equalityexpression { BinaryOperation And $1 $3 } equalityexpression : relationalexpression { $1 } | equalityexpression EQUAL relationalexpression { BinaryOperation CompareEqual $1 $3 }