芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/rentandbuyrealty.com/pay/vendor/hoa/compiler/Bin/Pp.php
getOption($v)) { switch ($c) { case 'v': switch (strtolower($v)) { case 'dump': $visitor = 'Hoa\Compiler\Visitor\Dump'; break; default: return $this->usage(); } break; case 'c': $visitor = str_replace('.', '\\', $v); break; case 's': $tokenSequence = true; break; case 't': $trace = true; break; case '__ambiguous': $this->resolveOptionAmbiguity($v); break; case 'h': case '?': default: return $this->usage(); } } $this->parser->listInputs($grammar, $language); if (empty($grammar) || (empty($language) && '0' !== $language)) { return $this->usage(); } $compiler = Compiler\Llk::load(new File\Read($grammar)); $stream = new File\Read($language); $data = $stream->readAll(); try { $ast = $compiler->parse($data); } catch (Compiler\Exception $e) { if (true === $tokenSequence) { $this->printTokenSequence($compiler, $data); echo "\n\n"; } throw $e; return 1; } if (true === $tokenSequence) { $this->printTokenSequence($compiler, $data); echo "\n\n"; } if (true === $trace) { $this->printTrace($compiler); echo "\n\n"; } if (null !== $visitor) { $visitor = Consistency\Autoloader::dnew($visitor); echo $visitor->visit($ast); } return; } /** * Print trace. * * @param \Hoa\Compiler\Llk\Parser $compiler Compiler. * @return void */ protected function printTrace(Compiler\Llk\Parser $compiler) { $i = 0; foreach ($compiler->getTrace() as $element) { if ($element instanceof Compiler\Llk\Rule\Entry) { $ruleName = $element->getRule(); $rule = $compiler->getRule($ruleName); echo str_repeat('> ', ++$i), 'enter ', $ruleName; if (null !== $id = $rule->getNodeId()) { echo ' (', $id, ')'; } echo "\n"; } elseif ($element instanceof Compiler\Llk\Rule\Token) { echo str_repeat(' ', $i + 1), 'token ', $element->getTokenName(), ', consumed ', $element->getValue(), "\n"; } else { echo str_repeat('< ', $i--), 'ekzit ', $element->getRule(), "\n"; } } return; } /** * Print token sequence. * * @param \Hoa\Compiler\Llk\Parser $compiler Compiler. * @param string $data Data to lex. * @return void */ protected function printTokenSequence(Compiler\Llk\Parser $compiler, $data) { $lexer = new Compiler\Llk\Lexer(); $sequence = $lexer->lexMe($data, $compiler->getTokens()); $format = '%' . (strlen((string) count($sequence)) + 1) . 's ' . '%-13s %-20s %s %6s' . "\n"; $header = sprintf( $format, '#', 'namespace', 'token name', 'token value ', 'offset' ); echo $header, str_repeat('-', strlen($header)), "\n"; foreach ($sequence as $i => $token) { printf( $format, $i, $token['namespace'], $token['token'], 30 < $token['length'] ? mb_substr($token['value'], 0, 29) . '…' : 'EOF' === $token['token'] ? str_repeat(' ', 30) : $token['value'] . str_repeat(' ', 30 - $token['length']), $token['offset'] ); } return; } /** * The command usage. * * @return int */ public function usage() { echo 'Usage : compiler:pp
[grammar.pp] [language]', "\n", 'Options :', "\n", $this->makeUsageOptionsList([ 'v' => 'Visitor name (only “dump” is supported).', 'c' => 'Visitor classname (using . instead of \ works).', 's' => 'Print token sequence.', 't' => 'Print trace.', 'help' => 'This help.' ]), "\n"; return; } } __halt_compiler(); Compile and visit languages with grammars.