當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SplStack::push方法代碼示例

本文整理匯總了PHP中SplStack::push方法的典型用法代碼示例。如果您正苦於以下問題:PHP SplStack::push方法的具體用法?PHP SplStack::push怎麽用?PHP SplStack::push使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SplStack的用法示例。


在下文中一共展示了SplStack::push方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: translate

 /**
  * Translate array sequence of tokens from infix to 
  * Reverse Polish notation (RPN) which representing mathematical expression.
  * 
  * @param array $tokens Collection of Token intances
  * @return array Collection of Token intances
  * @throws InvalidArgumentException
  */
 public function translate(array $tokens)
 {
     $this->operatorStack = new SplStack();
     $this->outputQueue = new SplQueue();
     for ($i = 0; $i < count($tokens); $i++) {
         $token = $tokens[$i];
         switch ($token->getType()) {
             case Token::T_OPERAND:
                 $this->outputQueue->enqueue($token);
                 break;
             case Token::T_OPERATOR:
             case Token::T_FUNCTION:
                 $o1 = $token;
                 $isUnary = $this->isPreviousTokenOperator($tokens, $i) || $this->isPreviousTokenLeftParenthesis($tokens, $i) || $this->hasPreviousToken($i) === false;
                 if ($isUnary) {
                     if ($o1->getValue() === '-' || $o1->getValue() === '+') {
                         $o1 = new Operator($o1->getValue() . 'u', 3, Operator::O_NONE_ASSOCIATIVE);
                     } else {
                         if (!$o1 instanceof FunctionToken) {
                             throw new \InvalidArgumentException("Syntax error: operator '" . $o1->getValue() . "' cannot be used as a unary operator or with an operator as an operand.");
                         }
                     }
                 } else {
                     while ($this->hasOperatorInStack() && ($o2 = $this->operatorStack->top()) && $o1->hasLowerPriority($o2)) {
                         $this->outputQueue->enqueue($this->operatorStack->pop());
                     }
                 }
                 $this->operatorStack->push($o1);
                 break;
             case Token::T_LEFT_BRACKET:
                 $this->operatorStack->push($token);
                 break;
             case Token::T_RIGHT_BRACKET:
                 if ($this->isPreviousTokenOperator($tokens, $i)) {
                     throw new \InvalidArgumentException('Syntax error: an operator cannot be followed by a right parenthesis.');
                 } elseif ($this->isPreviousTokenLeftParenthesis($tokens, $i)) {
                     throw new \InvalidArgumentException('Syntax error: empty parenthesis.');
                 }
                 while (!$this->operatorStack->isEmpty() && Token::T_LEFT_BRACKET != $this->operatorStack->top()->getType()) {
                     $this->outputQueue->enqueue($this->operatorStack->pop());
                 }
                 if ($this->operatorStack->isEmpty()) {
                     throw new \InvalidArgumentException('Syntax error: mismatched parentheses.');
                 }
                 $this->operatorStack->pop();
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf('Invalid token detected: %s.', $token));
                 break;
         }
     }
     while ($this->hasOperatorInStack()) {
         $this->outputQueue->enqueue($this->operatorStack->pop());
     }
     if (!$this->operatorStack->isEmpty()) {
         throw new InvalidArgumentException('Syntax error: mismatched parentheses or misplaced number.');
     }
     return iterator_to_array($this->outputQueue);
 }
開發者ID:oat-sa,項目名稱:lib-beeme,代碼行數:67,代碼來源:ShuntingYard.php

示例2: pushHandler

 /**
  * @inheritdoc
  */
 public function pushHandler(HandlerInterface ...$handlers)
 {
     $this->initHandlers();
     foreach ($handlers as $handler) {
         $this->handlers->push($handler);
     }
 }
開發者ID:oqq,項目名稱:minc-log,代碼行數:10,代碼來源:HandlerContainerTrait.php

示例3: evaluateRPN

 /**
  * Evaluate array sequence of tokens in Reverse Polish notation (RPN)
  * representing mathematical expression.
  * 
  * @param array $expressionTokens
  * @return float
  * @throws \InvalidArgumentException
  */
 private function evaluateRPN(array $expressionTokens)
 {
     $stack = new \SplStack();
     foreach ($expressionTokens as $token) {
         $tokenValue = $token->getValue();
         if (is_numeric($tokenValue)) {
             $stack->push((double) $tokenValue);
             continue;
         }
         switch ($tokenValue) {
             case '+':
                 $stack->push($stack->pop() + $stack->pop());
                 break;
             case '-':
                 $n = $stack->pop();
                 $stack->push($stack->pop() - $n);
                 break;
             case '*':
                 $stack->push($stack->pop() * $stack->pop());
                 break;
             case '/':
                 $n = $stack->pop();
                 $stack->push($stack->pop() / $n);
                 break;
             case '%':
                 $n = $stack->pop();
                 $stack->push($stack->pop() % $n);
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf('Invalid operator detected: %s', $tokenValue));
                 break;
         }
     }
     return $stack->top();
 }
開發者ID:aboyadzhiev,項目名稱:php-math-parser,代碼行數:43,代碼來源:Parser.php

示例4: pushProcessor

 /**
  * @inheritdoc
  */
 public function pushProcessor(ProcessorInterface ...$processors)
 {
     $this->initProcessors();
     foreach ($processors as $processor) {
         $this->processors->push($processor);
     }
 }
開發者ID:oqq,項目名稱:minc-log,代碼行數:10,代碼來源:ProcessorContainerTrait.php

示例5: startOrGroup

 public function startOrGroup()
 {
     $predicate = new OrPredicate(new NullPredicate());
     $this->predicateStack->top()->pushPredicate($predicate);
     $this->predicateStack->push($predicate);
     return $this;
 }
開發者ID:alchemy-fr,項目名稱:phraseanet-bundle,代碼行數:7,代碼來源:PredicateBuilder.php

示例6: LoadV2

 /**
  * 加載指定目錄下的配置並生成[絕對路徑=>配置]
  * (備用)
  *
  * @param        $filePath
  * @param string $ext
  */
 private function LoadV2($filePath, $ext = '.php')
 {
     $resConfig = [];
     $split = '.';
     if (file_exists($filePath)) {
         $key = basename($filePath, $ext);
         $configs = (include $filePath);
         $keyStack = new \SplStack();
         $keyStack->push([$key, $configs]);
         $whileCount = 0;
         //防止意外進入死循環,限製最多循環1024層
         while (!$keyStack->isEmpty() && $whileCount < 1024) {
             $whileCount++;
             $pair = $keyStack->pop();
             foreach ($pair[1] as $pairKey => $pairVal) {
                 if (is_array($pairVal)) {
                     $keyStack->push([$pair[0] . $split . $pairKey, $pairVal]);
                 } else {
                     $resConfig[$pair[0] . $split . $pairKey] = $pairVal;
                 }
             }
         }
     }
     return $resConfig;
 }
開發者ID:szyhf,項目名稱:DIServer,代碼行數:32,代碼來源:Base.php

示例7: parse

 public function parse($data)
 {
     $tokens = $this->tokenizer($data);
     $this->stack = new \SplStack();
     $this->stack->push(0);
     while (true) {
         $token = $tokens[0];
         $state = $this->stack->top();
         $terminal = $token[0];
         if (!isset($this->action[$state][$terminal])) {
             throw new \Exception('Token not allowed here (' . $token[1] . ')');
         }
         $action = $this->action[$state][$terminal];
         if ($action[0] === 0) {
             $this->stack->push($token[1]);
             $this->stack->push($action[1]);
             array_shift($tokens);
         } elseif ($action[0] === 1) {
             $value = $this->reduce($action[2], $action[1]);
             array_unshift($tokens, array($action[3], $value));
         } elseif ($action[0] === 2) {
             $this->stack->pop();
             return $this->stack->pop();
         } else {
             throw new \RuntimeException('Cannot compile');
         }
     }
     throw new \RuntimeException('Cannot compile. EOF');
 }
開發者ID:ftdebugger,項目名稱:jungle,代碼行數:29,代碼來源:Json.php

示例8: onElementStart

 /**
  * {@inheritdoc}
  */
 protected function onElementStart($parser, $name, $attributes)
 {
     $this->stack->push($name);
     if ($name === 'ITEM') {
         $this->currentRate = array();
     }
 }
開發者ID:RunOpenCode,項目名稱:exchange-rate-nbs,代碼行數:10,代碼來源:XmlParser.php

示例9: testPrintTraversable

 function testPrintTraversable()
 {
     $stack = new \SplStack();
     $stack->push('foo');
     $stack->push('bar');
     $this->assertEquals("<SplStack>['bar', 'foo']", ValuePrinter::serialize($stack));
 }
開發者ID:watoki,項目名稱:reflect,代碼行數:7,代碼來源:PrintValuesTest.php

示例10: registerCssFile

 public function registerCssFile($filename)
 {
     if (!isset($this->css_files)) {
         $this->css_files = new SplStack();
     }
     $this->css_files->push($filename);
 }
開發者ID:LumbaJack,項目名稱:Mercado-BTX,代碼行數:7,代碼來源:FakeAssetsRegistry.php

示例11: calculate

 public function calculate(array $variables)
 {
     $stack = new \SplStack();
     foreach ($this->reversePolandNotation as $token) {
         if ($token->getExpressionType() == ExpressionElementInterface::CONSTANT) {
             /** @var $token Constant */
             $stack->push($token->getValue());
         }
         if ($token->getExpressionType() == ExpressionElementInterface::VARIABLE) {
             /** @var $token Variable*/
             $variableName = $token->getValue();
             if (isset($variables[$variableName])) {
                 $stack->push($variables[$variableName]);
             } else {
                 throw new ExpressionParserException("Undefined variable: " . $variableName);
             }
         }
         if ($token->getExpressionType() == ExpressionElementInterface::OPERATOR) {
             /** @var $token OperatorInterface */
             $arg1 = $stack->pop();
             $arg2 = $stack->pop();
             $stack->push($token->calculate($arg1, $arg2));
         }
     }
     return $stack->top();
 }
開發者ID:podliy16,項目名稱:phpExpressionParser,代碼行數:26,代碼來源:ExpressionParser.php

示例12: startVisiting

 public function startVisiting($object)
 {
     if (!is_object($object)) {
         return;
     }
     $this->visitingSet->attach($object);
     $this->visitingStack->push($object);
 }
開發者ID:baardbaard,項目名稱:bb-twitterfeed,代碼行數:8,代碼來源:SerializationContext.php

示例13: start

 /**
  *  start profiling a block of code
  *  
  *  @param  string  $title  the name you are giving to this block of profiled code
  *  @return boolean pretty much always returns true
  */
 public function start($title)
 {
     $profile_map = array();
     $profile_map['start'] = microtime(true);
     $profile_map['title'] = $title;
     $this->stack_started->push($profile_map);
     return true;
 }
開發者ID:Jaymon,項目名稱:Montage,代碼行數:14,代碼來源:Profile.php

示例14: withMiddleware

 /**
  * {@inheritdoc}
  */
 public function withMiddleware($middleware) : StackContract
 {
     if ($middleware instanceof MiddlewareInterface || $middleware instanceof ServerMiddlewareInterface) {
         $this->stack->push($this->isContainerAware($middleware));
         return $this;
     }
     throw new LogicException('Unsupported middleware type.');
 }
開發者ID:narrowspark,項目名稱:framework,代碼行數:11,代碼來源:Dispatcher.php

示例15: enterNode

 /**
  * {@inheritdoc}
  */
 public function enterNode(Node $node)
 {
     if ($node instanceof Node\FunctionLike) {
         $this->loopStacks->push(new \SplStack());
     } elseif ($this->isTargetLoopNode($node)) {
         $this->getCurrentLoopStack()->push($node);
     }
 }
開發者ID:sstalle,項目名稱:php7cc,代碼行數:11,代碼來源:AbstractNestedLoopVisitor.php


注:本文中的SplStack::push方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。