Compress reduce rules

master
Vitaliy Filippov 2013-04-20 14:58:25 +04:00
parent 1b4a4c6d5c
commit ab902b4ac6
2 changed files with 23 additions and 5 deletions

View File

@ -666,9 +666,25 @@ class lime {
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'));
}
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() {
$s = array();

View File

@ -263,11 +263,13 @@ class parse_engine {
private function step_for($type) {
$row = $this->current_row();
if (!isset($row[$type])) {
return array('e', $this->stack->q);
if (isset($row[$type])) {
return explode(' ', $row[$type]);
}
return explode(' ', $row[$type]);
if (isset($row[''])) {
return explode(' ', $row['']);
}
return array('e', $this->stack->q);
}
private function get_steps() {
@ -281,7 +283,7 @@ class parse_engine {
list($opcode) = explode(' ', $row, 2);
if ($opcode != 'e') {
$out[] = $type;
$out[] = $type === '' ? '$default' : $type;
}
}