lib/ParserGenerator/PHP/ParserGenerator/Data.php
function CompressTables()
    {
        for ($i = 0; $i < $this->nstate; $i++) {
            $stp = $this->sorted[$i]->data;
            $nbest = 0;
            $rbest = 0;

            for ($ap = $stp->ap; $ap; $ap = $ap->next) {
                if ($ap->type != PHP_ParserGenerator_Action::REDUCE) {
                    continue;
                }
                $rp = $ap->x;
                if ($rp === $rbest) {
                    continue;
                }
                $n = 1;
                for ($ap2 = $ap->next; $ap2; $ap2 = $ap2->next) {
                    if ($ap2->type != PHP_ParserGenerator_Action::REDUCE) {
                        continue;
                    }
                    $rp2 = $ap2->x;
                    if ($rp2 === $rbest) {
                        continue;
                    }
                    if ($rp2 === $rp) {
                        $n++;
                    }
                }
                if ($n > $nbest) {
                    $nbest = $n;
                    $rbest = $rp;
                }
            }

            /* Do not make a default if the number of rules to default
            ** is not at least 1 */
            if ($nbest < 1) {
                continue;
            }


            /* Combine matching REDUCE actions into a single default */
            for ($ap = $stp->ap; $ap; $ap = $ap->next) {
                if ($ap->type == PHP_ParserGenerator_Action::REDUCE && $ap->x === $rbest) {
                    break;
                }
            }
            if ($ap === 0) {
                throw new Exception('$ap is not an object');
            }
            $ap->sp = PHP_ParserGenerator_Symbol::Symbol_new("{default}");
            for ($ap = $ap->next; $ap; $ap = $ap->next) {
                if ($ap->type == PHP_ParserGenerator_Action::REDUCE && $ap->x === $rbest) {
                    $ap->type = PHP_ParserGenerator_Action::NOT_USED;
                }
            }
            $stp->ap = PHP_ParserGenerator_Action::Action_sort($stp->ap);
        }
    }
function CompressTables()
    {
        for ($i = 0; $i < $this->nstate; $i++) {
            $stp = $this->sorted[$i]->data;
            $nbest = 0;
            $rbest = 0;

            for ($ap = $stp->ap; $ap; $ap = $ap->next) {
                if ($ap->type != PHP_ParserGenerator_Action::REDUCE) {
                    continue;
                }
                $rp = $ap->x;
                if ($rp === $rbest) {
                    continue;
                }
                $n = 1;
                for ($ap2 = $ap->next; $ap2; $ap2 = $ap2->next) {
                    if ($ap2->type != PHP_ParserGenerator_Action::REDUCE) {
                        continue;
                    }
                    $rp2 = $ap2->x;
                    if ($rp2 === $rbest) {
                        continue;
                    }
                    if ($rp2 === $rp) {
                        $n++;
                    }
                }
                if ($n > $nbest) {
                    $nbest = $n;
                    $rbest = $rp;
                }
            }

            /* Do not make a default if the number of rules to default
            ** is not at least 1 */
            if ($nbest < 1) {
                continue;
            }


            /* Combine matching REDUCE actions into a single default */
            for ($ap = $stp->ap; $ap; $ap = $ap->next) {
                if ($ap->type == PHP_ParserGenerator_Action::REDUCE && $ap->x === $rbest) {
                    break;
                }
            }
            if ($ap === 0) {
                throw new Exception('$ap is not an object');
            }
            $ap->sp = PHP_ParserGenerator_Symbol::Symbol_new("{default}");
            for ($ap = $ap->next; $ap; $ap = $ap->next) {
                if ($ap->type == PHP_ParserGenerator_Action::REDUCE && $ap->x === $rbest) {
                    $ap->type = PHP_ParserGenerator_Action::NOT_USED;
                }
            }
            $stp->ap = PHP_ParserGenerator_Action::Action_sort($stp->ap);
        }
    }
function CompressTables ( ) { for ( $ i = 0 ; $ i < $ this -> nstate ; $ i ++ ) { $ stp = $ this -> sorted [ $ i ] -> data ; $ nbest = 0 ; $ rbest = 0 ; for ( $ ap = $ stp -> ap ; $ ap ; $ ap = $ ap -> next ) { if ( $ ap -> type != PHP_ParserGenerator_Action :: REDUCE ) { continue ; } $ rp = $ ap -> x ; if ( $ rp === $ rbest ) { continue ; } $ n = 1 ; for ( $ ap2 = $ ap -> next ; $ ap2 ; $ ap2 = $ ap2 -> next ) { if ( $ ap2 -> type != PHP_ParserGenerator_Action :: REDUCE ) { continue ; } $ rp2 = $ ap2 -> x ; if ( $ rp2 === $ rbest ) { continue ; } if ( $ rp2 === $ rp ) { $ n ++ ; } } if ( $ n > $ nbest ) { $ nbest = $ n ; $ rbest = $ rp ; } } /* Do not make a default if the number of rules to default
            ** is not at least 1 */ if ( $ nbest < 1 ) { continue ; } /* Combine matching REDUCE actions into a single default */ for ( $ ap = $ stp -> ap ; $ ap ; $ ap = $ ap -> next ) { if ( $ ap -> type == PHP_ParserGenerator_Action :: REDUCE && $ ap -> x === $ rbest ) { break ; } } if ( $ ap === 0 ) { throw new Exception ( '$ap is not an object' ) ; } $ ap -> sp = PHP_ParserGenerator_Symbol :: Symbol_new ( "{default}" ) ; for ( $ ap = $ ap -> next ; $ ap ; $ ap = $ ap -> next ) { if ( $ ap -> type == PHP_ParserGenerator_Action :: REDUCE && $ ap -> x === $ rbest ) { $ ap -> type = PHP_ParserGenerator_Action :: NOT_USED ; } } $ stp -> ap = PHP_ParserGenerator_Action :: Action_sort ( $ stp -> ap ) ; } }
Reduce the size of the action tables, if possible, by making use
of defaults.

In this version, we take the most frequent REDUCE action and make
it the default.
Reduce the size of the action tables if possible by making use of defaults .