fabpot/Twig — Issue #583: Unary +/- operators need a higher precedence as binary operators
Author: akkie
Created: 2012-01-06 12:08:43+00:00
State: open

The unary +/- operators need a higher precedence as the binary operators. This is a limitation of the "Precedence climbing" algorithm described in the [Wikipedia article](http://en.wikipedia.org/wiki/Operator-precedence_parser).

> A limitation to this strategy is that unary operators must all have higher precedence than infix operators.

An other article from the [ANTLR mailing list](http://www.antlr.org/pipermail/antlr-dev/2009-April/002255.html) describes the same problem.

You can test this issue with the following code:

```php
render('{{ 4 / -1 * 5 }}');

```

The expected result is -20 but the example result is -0.8