本文整理汇总了PHP中SplStack::top方法的典型用法代码示例。如果您正苦于以下问题:PHP SplStack::top方法的具体用法?PHP SplStack::top怎么用?PHP SplStack::top使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplStack
的用法示例。
在下文中一共展示了SplStack::top方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLastEntry
/**
* {@inheritdoc}
*/
public function getLastEntry() : EntryInterface
{
if (0 === $this->stack->count()) {
throw new \RuntimeException('Trace empty');
}
return $this->stack->top();
}
示例2: 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');
}
示例3: onElementData
/**
* {@inheritdoc}
*/
protected function onElementData($parser, $data)
{
if (!empty($data)) {
switch ($this->stack->top()) {
case 'DATE':
$this->date = \DateTime::createFromFormat('d.m.Y', $data);
break;
case 'TYPE':
$data = trim($data);
if ($data === 'FOREIGN EXCHANGE') {
$this->rateType = 'foreign_exchange';
} elseif ($data === 'FOREIGN CASH') {
$this->rateType = 'foreign_cash';
}
break;
case 'CURRENCY':
$this->currentRate['currencyCode'] = trim($data);
break;
case 'UNIT':
$this->currentRate['unit'] = (int) trim($data);
break;
case 'BUYING_RATE':
$this->currentRate['buyingRate'] = (double) trim($data);
break;
case 'SELLING_RATE':
$this->currentRate['sellingRate'] = (double) trim($data);
break;
case 'MIDDLE_RATE':
$this->currentRate['middleRate'] = (double) trim($data);
break;
}
}
}
示例4: startOrGroup
public function startOrGroup()
{
$predicate = new OrPredicate(new NullPredicate());
$this->predicateStack->top()->pushPredicate($predicate);
$this->predicateStack->push($predicate);
return $this;
}
示例5: enterNode
/**
* {@inheritdoc}
*/
public function enterNode(Node $node)
{
$isCurrentNodeFunctionLike = $node instanceof Node\FunctionLike;
if ($isCurrentNodeFunctionLike || $this->argumentModificationStack->isEmpty() || !$this->argumentModificationStack->top() || !$this->functionAnalyzer->isFunctionCallByStaticName($node, array_flip(array('func_get_arg', 'func_get_args')))) {
$isCurrentNodeFunctionLike && $this->argumentModificationStack->push(false);
return;
}
/** @var Node\Expr\FuncCall $node */
$functionName = $node->name->toString();
$this->addContextMessage(sprintf('Function argument(s) returned by "%s" might have been modified', $functionName), $node);
}
示例6: toPostfix
/**
* Conversão de Formato Infixo para Posfixo
* @return array Fila de Tokens para Cálculo Posfixo
*/
public function toPostfix()
{
/* Analisador Léxico */
$lexer = $this->getLexer();
/* Pilha para Conversão */
$stack = new \SplStack();
/* Notação Polonesa Reversa */
$postfix = array();
/* Execução */
while (($token = $lexer->getToken()) != null) {
/* Analisador Sintático */
if ($token->isA('T_NUMBER') || $token->isA('T_FLOAT') || $token->isA('T_VAR') || $token->isA('T_DEF') || $token->isA('T_BLOCKDEF')) {
$postfix[] = $token;
} elseif ($token->isA('T_OPERATOR') || $token->isA('T_ASSIGN')) {
/* @todo Melhorar Pesquisa */
$found = false;
while (!$found) {
if ($stack->isEmpty()) {
$stack->push($token);
$found = true;
} else {
if ($stack->top()->isA('T_OB')) {
$stack->push($token);
$found = true;
} elseif ($this->precedence($token, $stack->top()) > 0) {
$stack->push($token);
$found = true;
} else {
$postfix[] = $stack->pop();
}
}
}
} elseif ($token->isA('T_OB')) {
$stack->push($token);
} elseif ($token->isA('T_CB')) {
while (!$stack->isEmpty() && !$stack->top()->isA('T_OB')) {
$postfix[] = $stack->pop();
}
$stack->pop();
} else {
$format = "Invalid Token '%s' @column %d";
$message = sprintf($format, $token->getType(), $token->getPosition());
throw new Exception($message);
}
}
/* Tokens Restantes na Pilha */
while (!$stack->isEmpty()) {
$postfix[] = $stack->pop();
}
return $postfix;
}
示例7: getCallerStatedClassName
/**
* To get the class name of the caller according to scope visibility.
*
* @return string
*/
private function getCallerStatedClassName() : string
{
if (true !== $this->callerStatedClassesStack->isEmpty()) {
return $this->callerStatedClassesStack->top();
}
return '';
}
示例8: suite
/**
* Get the current suite
*
* @static
* @return \DrSlump\Spec\TestSuite
*/
public static function suite()
{
if (self::$suites->isEmpty()) {
return null;
}
return self::$suites->top();
}
示例9: processSystemVar
/**
* A hook to the $system special variable. Returns the
* compiled PHP code for the call.
*
* @internal
* @param array $namespace The namespace to parse
* @return string
*/
public function processSystemVar($opt)
{
if ($this->_stack->count() == 0) {
throw new Opt_SysVariableInvalidUse_Exception('$' . implode('.', $opt), 'components');
}
return $this->_stack->top() . '->get(\'' . $opt[2] . '\')';
}
示例10: _applyModifiers
/**
* Apply modifiers to the modifiers stack
*
* @param string $modifiers Modifiers to apply
*
* @return void
*/
protected function _applyModifiers($modifiers)
{
$currentModifiers = $this->_modifiersStack->top();
//If $modifiers is an empty string just take current modifiers and
//add them to the modifiers stack
//Othwerwise
if ($modifiers !== "") {
//Explode modifiers with the dash, the first group of modifiers
//represents the modifiers to add, every following group represents
//the modifiers to subtract
$groups = explode("-", $modifiers);
foreach ($groups as $k => $group) {
if (!$group) {
continue;
}
$len = strlen($group);
for ($i = 0; $i < $len; $i++) {
$contains = strpos($currentModifiers, $group[$i]) !== false;
if (!$k && !$contains) {
$currentModifiers .= $group[$i];
} elseif ($k && $contains) {
$currentModifiers = str_replace($group[$i], "", $currentModifiers);
}
}
}
//Remove the last entry in modifiers stack
$this->_modifiersStack->pop();
}
//Add calculated modifiers to the top of the modifiers stack
$this->_modifiersStack->push($currentModifiers);
}
示例11: last
/**
* Convenient access to the last handler return value.
*
* If the collection is empty, returns null. Otherwise, returns value
* returned by last handler.
*
* @return mixed The last handler return value
*/
public function last()
{
if (count($this) === 0) {
return null;
}
return parent::top();
}
示例12: endElement
/**
* When we reach a closing element do something.
*
* This is mostly used to add stuff to the end of a statement, like putting new lines where div tags close
*
* @see xml_set_element_handler()
*
* @param resource $parser
* @param string $name
*/
public function endElement($parser, $name)
{
switch ($name) {
case 'P':
$this->appendBlockText("\n\n");
break;
case 'UL':
$this->appendBlockText("\n\n");
break;
case 'LI':
$this->appendBlockText("\n");
break;
case 'DIV':
$this->appendBlockText("\n\n\n");
break;
case 'A':
$attrs = $this->blockAttributesStack->top();
if (isset($attrs['HREF'])) {
$this->appendBlockText(" ({$attrs['HREF']})");
}
}
$blockContent = $this->blockFinished();
if (count($this->transformedTextStack)) {
$this->appendBlockText($blockContent);
} else {
$this->text .= $blockContent;
}
}
示例13: 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();
}
示例14: topOfStack
/**
* Returns the form stack head element. If the stack is empty,
* the method returns NULL.
*
* @internal
* @static
* @return Opf_Form
*/
public static function topOfStack()
{
if (self::$_stack === null) {
self::$_stack = new SplStack();
}
if (self::$_stack->count() == 0) {
return null;
}
return self::$_stack->top();
}
示例15: SplQueue
function infix_to_rpn($tokens)
{
$out_q = new SplQueue();
$stack = new SplStack();
$index = 0;
while (count($tokens) > $index) {
$t = $tokens[$index];
switch ($t) {
case !in_array($t, self::operators_dictionary):
$out_q->enqueue($t);
break;
case $t == "not":
case $t == "and":
case $t == "or":
$stack->push($t);
break;
case $t == "(":
$stack->push($t);
break;
case $t == ")":
while ($stack->top() != "(") {
$out_q->enqueue($stack->pop());
}
$stack->pop();
if ($stack->count() > 0 && $stack->top() == "not") {
$out_q->enqueue($stack->pop());
}
break;
default:
break;
}
++$index;
}
while ($stack->count() > 0) {
$out_q->enqueue($stack->pop());
}
$reversed_q = array();
foreach ($out_q as $value) {
$reversed_q[] = $value;
}
return array_reverse($reversed_q);
}