handle both left and right associativity