diff --git a/Test/TestParser.hs b/Test/TestParser.hs index 1caec8f..acb7ee7 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -84,6 +84,13 @@ testReturnVoid = TestCase $ assertEqual "expect block with return nothing" (Block [Return Nothing]) $ parseBlock [LBRACKET,RETURN,SEMICOLON,RBRACKET] +testExpressionNot = TestCase $ + assertEqual "expect expression not" (UnaryOperation Not (Reference "boar")) $ + parseExpression [NOT,IDENTIFIER "boar"] +testExpressionMinus = TestCase $ + assertEqual "expect expression minus" (UnaryOperation Minus (Reference "boo")) $ + parseExpression [MINUS,IDENTIFIER "boo"] + tests = TestList [ testSingleEmptyClass, testTwoEmptyClasses, @@ -108,5 +115,7 @@ tests = TestList [ testFieldWithInitialization, testLocalBoolWithInitialization, testFieldNullWithInitialization, - testReturnVoid + testReturnVoid, + testExpressionNot, + testExpressionMinus ] \ No newline at end of file diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index c92f6f1..61bd1f1 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -298,12 +298,12 @@ fieldaccess : primary DOT IDENTIFIER { } unaryexpression : unaryexpressionnotplusminus { $1 } -- | predecrementexpression { } - -- | PLUS unaryexpression { } - -- | MINUS unaryexpression { } + | PLUS unaryexpression { $2 } + | MINUS unaryexpression { UnaryOperation Minus $2 } -- | preincrementexpression { $1 } postfixexpression : primary { $1 } - -- | name { } + | name { Reference $1 } -- | postincrementexpression { } -- | postdecrementexpression{ } @@ -321,7 +321,7 @@ primarynonewarray : literal { $1 } unaryexpressionnotplusminus : postfixexpression { $1 } -- | TILDE unaryexpression { } - -- | EXCLMARK unaryexpression { } + | EXCLMARK unaryexpression { UnaryOperation Not $2 } -- | castexpression{ } exclusiveorexpression : andexpression { $1 }