/** * Scans the current tokens for operators by the order they are * in $precedences and creates scopes for each expression next to * those operators * * @param array $precedences * @return void */ protected function precedenceShiftTokens($precedences) { $operator = array_shift($precedences); if (!$operator) { return; } if (in_array($operator, $this->tokens, true)) { $this->operator = $operator; $tokens = $this->tokens; $this->tokens = array($scope = new self()); foreach ($tokens as $token) { if ($token === $this->operator) { $this->tokens[] = $scope = new self(); } else { $scope->pushToken($token); } } foreach ($this->tokens as $scope) { $scope->precedenceShiftTokens($precedences); } } $this->precedenceShiftTokens($precedences); }