本文整理汇总了PHP中Parser::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::init方法的具体用法?PHP Parser::init怎么用?PHP Parser::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser::init方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* Initializer
*
* Sets up the Graph class with an image width and height defaults to
* 640x480
*
* @param Integer $width Image width
* @param Integer $height Image height
*/
public static function init($width = 640, $height = 480)
{
// default width and height equal to that of a poor monitor (in early 2000s)
self::$width = $width;
self::$height = $height;
//initialize main class
Parser::init();
}
示例2: init
/**
* init the class
*
* @since 3.0.0
*
* @param string $mode name of the mode
*
* @return mixed
*/
public function init($mode = null)
{
$parser = new Parser($this->_request);
$parser->init($mode);
/* run command */
$commandKey = $parser->getArgument(0);
if (array_key_exists($commandKey, $this->_namespaceArray)) {
$commandClass = $this->_namespaceArray[$commandKey];
if (class_exists($commandClass)) {
$command = new $commandClass($this->_registry, $this->_request, $this->_config);
return $command->run($mode);
}
}
return false;
}
示例3: testDumpLoad
function testDumpLoad()
{
$tokens = ['d' => '[0-9]+', 'a', 'b', 'c', 'sp' => '\\s+'];
$rules = ['A' => [[['d', ['+', ['|', 'a', 'b']], 'B'], true]], 'B' => [[['d'], true]]];
$lexer = new Lexer($tokens);
$parser = new Parser();
$parser->setLexer($lexer);
$parser->init($rules);
$parser->setSkipTokens(['sp']);
$data = $parser->dump();
$s = serialize($data);
$e = var_export($data, true);
$parser = new Parser();
$parser->setLexer($lexer);
$v = eval("return {$e};");
$parser->load($v);
$parser->tree('123 a a b 1244');
$parser = new Parser();
$parser->setLexer($lexer);
$data = unserialize($s);
$parser->load($data);
$parser->tree('123 a a b 1244');
ob_start();
$parser->printTree('123 a a b 1244');
$text = ob_get_clean();
$this->assertTrue(is_string($text));
}
示例4: parse
/**
* main entry function
* @param array input tokens
* @return LRParseNode parse tree
*/
function parse(array $input)
{
// Parser class initialized input in standard fashion
parent::init($input);
// we always start at state 1
$state = 1;
// repeat until success or failure
// if table is correct, this cannot get into infinite loop
while (true) {
//echo "\nState #$state, Symbol \"",$this->Lex->name($this->t),"\" \n";
//echo "Permitted: [", $this->Lex->implode( ', ', $this->Table->permitted( $state, $this->Grammar )) ,"]\n";
//echo "Stack: [",$this->Lex->implode(', ',$this->stack),"] \n";
// get next action based up on current terminal in input stream
$n = $this->Table->lookup($state, $this->t);
if (is_null($n)) {
$this->badtoken = $this->tok;
// display which terminal symbols would be permitted
$expected = $this->Table->permitted($state, $this->Grammar);
if (!empty($expected)) {
$expected = 'expecting "' . $this->Lex->implode('", or "', $expected) . '"';
} else {
$expected = 'no terminals permitted';
}
if (isset($this->stack[0])) {
$Node = end($this->stack);
if ($this->fail('after "%s" %s in state #%u', $this->Lex->name($Node->scalar_symbol()), $expected, $state)) {
continue;
} else {
break;
}
} else {
if ($this->fail('%s in state #%u', $expected, $state)) {
continue;
} else {
break;
}
}
}
// Odd numbers are states, even numbers are rules
if ($n & 1) {
// SHIFT
if ($this->t === P_EOF) {
$len = count($this->stack);
if ($len !== 1) {
if ($this->fail('premature EOF stack has %u elements', $len)) {
continue;
} else {
break;
}
}
// Full parse
return $this->stack[0];
}
// shift, and move to next state
$state = $this->shift($state, $n);
} else {
// REDUCE, and move to previous state
$state = $this->reduce($state, $n);
}
}
}