auriocus / VecTcl

Numeric array and linear algebra extension for Tcl
http://auriocus.github.io/VecTcl
Other
34 stars 9 forks source link

Logical operator precedence wrong ? #3

Closed apnadkarni closed 9 years ago

apnadkarni commented 9 years ago

Seems to be the precedence of && and || is incorrect (where incorrect means inconsistent with other languages including Tcl's expr)

% A = 0
{0}
% B = 1
{1}
% C = 1
{1}
% A && B || C
{0}
% B || C && A
{0}

Compare with

% set a 0 ; set b 1 ; set c 1
1
% expr {$a && $b || $c}
1
% expr {$b || $c && $a}
1
auriocus commented 9 years ago

Thank you for reporting this problem. Indeed the precedence is swapped, which can be proven by inspecting the compiler output:

% vectcl::compile { A && B || C }
upvar 1 A A
upvar 1 B B
upvar 1 C C
numarray::&& [set A] [numarray::|| [set B] [set C]]

It seems to be an error in the grammar.

auriocus commented 9 years ago

Fixed in HEAD