Пример #1
0
 /**
  * Leafに対して渡したいもの:
  *   ZendTokenのインスタンス
  *   開始行
  * not-Leafに対して渡したいもの
  *   このノードの呼び名
  *   子供のNodeたち
  */
 function __construct($token = '', $children = null, $current_line = 0)
 {
     if ($children === null) {
         // 木構造でいうleaf
         $zend_token = $token;
         $this->zendToken = $zend_token;
         $this->endLine = $current_line;
         $this->beginLine = $current_line - $this->zendToken->getNewLines();
         $this->children = array();
         $token_name = $zend_token->tokenValue;
     } elseif (is_array($children)) {
         // 木構造でいうleaf以外
         if ($children !== array()) {
             $first_child = $children[0];
             $last_child = $children[sizeof($children) - 1];
             $this->zendToken = null;
             $this->beginLine = $first_child->beginLine;
             $this->endLine = $first_child->endLine;
             $this->children = $children;
         }
         $token_name = $token;
     } else {
     }
     $this->tokenName = $token_name;
     $ev = new sfEvent($this, $token_name);
     EventDispatcherHolder::getDispatcher()->notify($ev);
     $ev_all = new sfEvent($this, 'ALL_NODE');
     EventDispatcherHolder::getDispatcher()->notify($ev_all);
 }
Пример #2
0
 static function getDispatcher()
 {
     if (!self::$dispatcher) {
         self::$dispatcher = new sfEventDispatcher();
     }
     return self::$dispatcher;
 }
Пример #3
0
#!/usr/bin/env php
<?php 
require_once dirname(__FILE__) . '/../libs/PhpLexer.php';
require_once dirname(__FILE__) . '/../libs/PhpParser.php';
require_once dirname(__FILE__) . '/../libs/EventDispatcherHolder.php';
if ($_SERVER['argc'] <= 1) {
    echo "usage: ./show-php-parse-tree.php [php program]\n";
    exit(0);
}
$input_file = $_SERVER['argv'][1];
if (!file_exists($input_file)) {
    echo "error: no such file\n";
    exit(1);
}
EventDispatcherHolder::getDispatcher()->connect('start', 'output_dot_from_parser_tree');
$l = new PhpLexer();
$l->setPhpSource(file_get_contents($input_file));
$p = new PhpParser();
$p->yyparse($l);
function output_dot_from_parser_tree(sfEvent $ev)
{
    $node = $ev->getSubject();
    output_header();
    output_node_info($node);
    output_children($node);
    output_footer();
}
function output_header()
{
    echo 'digraph sample {
  node [shape = record, style = filled,