mirror of https://github.com/vitalif/lime
Compress reduce rules
parent
1b4a4c6d5c
commit
ab902b4ac6
16
lime.php
16
lime.php
|
@ -666,9 +666,25 @@ class lime {
|
||||||
throw new Bug($this->expect_conflicts .' conflicts expected, got ' . $this->conflicts);
|
throw new Bug($this->expect_conflicts .' conflicts expected, got ' . $this->conflicts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->compress($i);
|
||||||
|
|
||||||
return $this->lang->ptab_to_class($this->parser_class, compact('a', 'qi', 'i', 'd'));
|
return $this->lang->ptab_to_class($this->parser_class, compact('a', 'qi', 'i', 'd'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function compress(&$i) {
|
||||||
|
foreach ($i as &$inst) {
|
||||||
|
$act = reset($inst);
|
||||||
|
if (substr($act, 0, 2) == 'r ') {
|
||||||
|
foreach ($inst as $k => $a) {
|
||||||
|
if ($a !== $act) {
|
||||||
|
continue(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$inst = array('' => $act);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function rule_table() {
|
function rule_table() {
|
||||||
$s = array();
|
$s = array();
|
||||||
|
|
||||||
|
|
|
@ -263,12 +263,14 @@ class parse_engine {
|
||||||
|
|
||||||
private function step_for($type) {
|
private function step_for($type) {
|
||||||
$row = $this->current_row();
|
$row = $this->current_row();
|
||||||
if (!isset($row[$type])) {
|
if (isset($row[$type])) {
|
||||||
return array('e', $this->stack->q);
|
|
||||||
}
|
|
||||||
|
|
||||||
return explode(' ', $row[$type]);
|
return explode(' ', $row[$type]);
|
||||||
}
|
}
|
||||||
|
if (isset($row[''])) {
|
||||||
|
return explode(' ', $row['']);
|
||||||
|
}
|
||||||
|
return array('e', $this->stack->q);
|
||||||
|
}
|
||||||
|
|
||||||
private function get_steps() {
|
private function get_steps() {
|
||||||
$out = array();
|
$out = array();
|
||||||
|
@ -281,7 +283,7 @@ class parse_engine {
|
||||||
|
|
||||||
list($opcode) = explode(' ', $row, 2);
|
list($opcode) = explode(' ', $row, 2);
|
||||||
if ($opcode != 'e') {
|
if ($opcode != 'e') {
|
||||||
$out[] = $type;
|
$out[] = $type === '' ? '$default' : $type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue