diff --git a/src/parser/Parser.ts b/src/parser/Parser.ts index 677f6078..07eeee30 100644 --- a/src/parser/Parser.ts +++ b/src/parser/Parser.ts @@ -1385,10 +1385,14 @@ export class Parser { } function prefixUnary(): Expression { - if (match(Lexeme.Not, Lexeme.Minus, Lexeme.Plus)) { + if (match(Lexeme.Not)) { let operator = previous(); let right = relational(); return new Expr.Unary(operator, right); + } else if (match(Lexeme.Minus, Lexeme.Plus)) { + let operator = previous(); + let right = prefixUnary(); + return new Expr.Unary(operator, right); } return call(); diff --git a/test/e2e/Syntax.test.js b/test/e2e/Syntax.test.js index f55fc39b..5866ede5 100644 --- a/test/e2e/Syntax.test.js +++ b/test/e2e/Syntax.test.js @@ -75,6 +75,16 @@ describe("end to end syntax", () => { ]); }); + test("negative-precedence.brs", async () => { + await execute([resourceFile("negative-precedence.brs")], outputStreams); + + expect(allArgs(outputStreams.stdout.write).filter((arg) => arg !== "\n")).toEqual([ + "0000", + "0", + "foo is not 1", + ]); + }); + test("assignment.brs", async () => { await execute([resourceFile("assignment.brs")], outputStreams); diff --git a/test/e2e/resources/negative-precedence.brs b/test/e2e/resources/negative-precedence.brs new file mode 100644 index 00000000..122836da --- /dev/null +++ b/test/e2e/resources/negative-precedence.brs @@ -0,0 +1,15 @@ +Sub Main() + x = 96 + y = 56 + w = 1088 + h = 608 + Offset(-x + 96, -y + 56, -w + 1088, -h + 608) + print -1000 +1000 + foo = 5 + if not foo = 1 + print "foo is not 1" + end if +End Sub +Sub Offset(x, y, w, h) + print x.toStr() + y.toStr() + w.toStr() + h.toStr() +End Sub \ No newline at end of file