Example #1
0
 /**
  * Get AST of the token representation.
  *
  * @return  \Hoa\Compiler\Llk\TreeNode
  */
 public function getAST()
 {
     if (null === static::$_regexCompiler) {
         $stream = new File\Read('hoa://Library/Regex/Grammar.pp');
         $stream->rewind();
         static::$_regexCompiler = Compiler\Llk::load($stream);
     }
     if (null === $this->_ast) {
         $this->_ast = static::$_regexCompiler->parse($this->getRepresentation());
     }
     return $this->_ast;
 }
Example #2
0
 /**
  * Print token sequence.
  *
  * @param   \Hoa\Compiler\Llk\Parser  $compiler    Compiler.
  * @return  void
  */
 protected function printTokenSequence(Compiler\Llk\Parser $compiler)
 {
     $sequence = $compiler->getTokenSequence();
     $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;
 }
Example #3
0
 /**
  * {@inheritDoc}
  */
 public function interpret($rule)
 {
     return $this->visit($this->compiler->parse($rule));
 }
Example #4
0
 /**
  * Construct a generator.
  *
  * @param   \Hoa\Compiler\Llk\Parser  $compiler        Compiler/parser.
  * @param   \Hoa\Visitor\Visit        $tokenSampler    Token sampler.
  * @return  void
  */
 public function __construct(Compiler\Llk\Parser $compiler, Visitor\Visit $tokenSampler)
 {
     $this->_compiler = $compiler;
     $this->_tokens = $compiler->getTokens();
     $this->_rules = $compiler->getRules();
     $this->_tokenSampler = $tokenSampler;
     $this->_rootRuleName = $compiler->getRootRule();
     return;
 }