当前位置: 首页>>代码示例>>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;未经允许,请勿转载。