diff --git a/src/parser/DeclParser.cj b/src/parser/DeclParser.cj index 782dc86..08b88a9 100644 --- a/src/parser/DeclParser.cj +++ b/src/parser/DeclParser.cj @@ -854,6 +854,11 @@ internal open class DeclParser { // the problem will be solved. if (helper.matches(TKH.PREFIX_UNARY_OPERATOR)) { let oper: Token = helper.previous() + if (oper.kind == TK.SUB && helper.matches(TK.INTEGER_LITERAL, TK.FLOAT_LITERAL)) { + let literal: Token = helper.previous() + return LitConstExpr(NodeIdManager.nextId(), + Token(literal.kind, "-" + literal.value, oper.pos)) + } let right: Expr = expectExpression(prefixUnaryExpression, "Expected a postfixExpression after ${oper.value}, found '\u{001b}[31m${helper.peek().value}\u{001b}[0m'") return UnaryExpr(NodeIdManager.nextId(), oper, right) diff --git a/src/test/Parser_test.cj b/src/test/Parser_test.cj index 74b463e..cc214ea 100644 --- a/src/test/Parser_test.cj +++ b/src/test/Parser_test.cj @@ -253,7 +253,7 @@ class ParserTests { func unaryExpr_test() { let test: String = """ main(){ - -134 + -(134) !134 }""" @@ -278,9 +278,11 @@ class ParserTests { let test: String = """ main(){ 1231 + -1231 "string" () 1.2 + -1.2 true false r'a'