我正在阅读柠檬解析器的 PHP 移植:
for ($i = 0; $i < $this->nstate; $i++) { /* Loop over all states */
$stp = $this->sorted[$i]->data;
for ($cfp = $stp->cfp; $cfp; $cfp = $cfp->next) {
/* Loop over all configurations */
if ($cfp->rp->nrhs == $cfp->dot) { /* Is dot at extreme right? */
for ($j = 0; $j < $this->nterminal; $j++) {
if (isset($cfp->fws[$j])) {
/* Add a reduce action to the state "stp" which will reduce by the
** rule "cfp->rp" if the lookahead symbol is "$this->symbols[j]" */
PHP_ParserGenerator_Action::Action_add($stp->ap, PHP_ParserGenerator_Action::REDUCE,
$this->symbols[$j], $cfp->rp);
}
}
}
}
}
在我看来,解析器是一个 SLR(1) 解析器,根据它如何计算动作表,但是@the home page of lemon,它证明自己是一个 LALR(1) 解析器:
http://www.hwaci.com/sw/lemon/
是 SLR(1) 还是 LALR(1) ?