Exemple #1
0
 /**
  * Debugging function
  * @param Lex
  * @param Grammar
  * @return void
  */
 function dump(Lex $Lex, Grammar $Grammar)
 {
     list($lhs, $rhs) = $this->rule;
     echo $Lex->name($lhs), "->";
     foreach ($rhs as $i => $s) {
         if ($i === $this->i) {
             echo '•';
         } else {
             if ($i !== 0) {
                 echo ',';
             }
         }
         $t = $Lex->name($s);
         echo $t === $s ? var_export($s, 1) : $t;
     }
     if (is_null($this->current_symbol())) {
         // accepting state
         echo '•';
     }
     if (isset($this->la)) {
         echo ' [', $Lex->name($this->la), ']';
     }
 }
Exemple #2
0
 /**
  * @ignore
  */
 function dump(Lex $Lex)
 {
     $t = max(2, strlen((string) $this->i));
     foreach ($this->rules as $i => $rule) {
         $lhs = $Lex->name($rule[0]);
         $rhs = $Lex->implode(' ', $rule[1]);
         $i = str_pad($i, $t, ' ', STR_PAD_LEFT);
         echo "{$i}: {$lhs} -> {$rhs} \n";
     }
     if ($this->excludela) {
         echo "Special rules:\n";
         foreach ($this->excludela as $nt => $a) {
             echo ' ', $Lex->name($nt), ' ~{ ', $Lex->implode(' ', $a), " }\n";
         }
     }
 }
 /**
  * @internal
  * @return void
  */
 function dump(Lex $Lex, Grammar $Grammar, $tab = '')
 {
     echo "{$tab}LRStation #{$this->id}\n";
     echo "{$tab}[", $Lex->name($this->nt);
     if (isset($this->la)) {
         echo ' ' . $Lex->name($this->la);
     }
     echo "]\n";
     if (isset($this->__dumped)) {
         echo "{$tab}--recursion--\n";
         return;
     }
     $this->__dumped = true;
     foreach ($this->etransitions as $State) {
         echo "{$tab}--->\n";
         $State->dump($Lex, $Grammar, "{$tab} . ");
     }
 }
 /**
  * Debugging function, makes table legible
  * @param Lex
  * @param Grammar
  * @param int optionally dump specific row (state)
  * @return void
  */
 function dump(Lex $Lex, Grammar $Grammar, $state = null)
 {
     $table = array();
     $heads = array('' => 0);
     // translate cell data and get other meta data
     foreach ($this->table as $i => $row) {
         if (!is_null($state) && $i !== $state) {
             continue;
         }
         $table[$i] = array();
         // create row header
         $table[$i][''] = "#{$i}";
         $heads[''] = max($heads[''], strlen($table[$i]['']));
         // iterate over cols in this row
         foreach ($row as $sym => $entry) {
             if (is_null($sym)) {
                 $sym = 'null';
             } else {
                 $sym = $Lex->name($sym);
             }
             // rules are event, states are odd
             if ($entry & 1) {
                 $str = " #{$entry} ";
             } else {
                 list($nt, $rhs) = $Grammar->get_rule($entry);
                 $str = ' ' . $Lex->name($nt) . ' -> ';
                 foreach ($rhs as $t) {
                     $str .= $Lex->name($t) . ' ';
                 }
             }
             // insert cell
             $table[$i][$sym] = $str;
             // collect known column header with max cell width in column
             if (!isset($heads[$sym])) {
                 $heads[$sym] = strlen($sym);
             }
             $heads[$sym] = max($heads[$sym], strlen($str));
         }
     }
     // print all headers
     $a = array();
     $b = array();
     foreach ($heads as $sym => $len) {
         $b[] = str_repeat('-', $len);
         $a[] = str_pad($sym, $len, ' ', STR_PAD_BOTH);
     }
     echo '+', implode('+', $b), "+\n";
     echo '|', implode('|', $a), "|\n";
     foreach ($table as $i => $row) {
         $c = array();
         foreach ($heads as $sym => $len) {
             if (isset($table[$i][$sym])) {
                 $c[] = str_pad($row[$sym], $len, ' ', STR_PAD_BOTH);
             } else {
                 $c[] = str_repeat(' ', $len);
             }
         }
         echo '+', implode('+', $b), "+\n";
         echo '|', implode('|', $c), "|\n";
     }
     echo '+', implode('+', $b), "+\n";
 }
 /**
  * Debugging function to inspect the node tree
  * @return void
  */
 function dump(Lex $Lex, $tab = '')
 {
     $tag = $Lex->name($this->t);
     if ($this->is_terminal()) {
         if ($this->value && $this->value !== $this->t) {
             echo $tab, '<', $tag, ">\n   ", $tab, htmlspecialchars($this->value), "\n", $tab, '</', $tag, ">\n";
         } else {
             echo $tab, htmlspecialchars($this->value), "\n";
         }
     } else {
         if (!$this->length) {
             echo $tab, '<', $tag, " />\n";
         } else {
             echo $tab, '<', $tag, ">\n";
             foreach ($this->children as $Child) {
                 $Child->dump($Lex, "   " . $tab);
             }
             echo $tab, '</', $tag, ">\n";
         }
     }
 }