stack = []
push ($) //$: end of file
push (1) // 1: initial state
while (true)
{
token t = nextToken()
state s = stack[top]
if (ACTION[s, t] == 'si')
{
push (t); push(i);
}
else if (ACTION[s, t] == 'si')
{
pop (the right hand of production 'j': X -> B'')
state s = stack[top]
push(X); push(GOTO[s, X])
}
else
{
error(...)
}
}
Closure
- 假设看到A→β∙Bγ,也就是当前看到了B,其中
B 是非终结符,那么显然窝们也希望看到由B产生的产生式,也就是希望有B→ω... 这样的式子来告诉窝们,可以期待看到ω。如此,就需要把形如B→ω...的产生式也加入。这样不断地添加,知道找不到上述形式的产生式为止,那么这些产生式就构成了Closure(A−>β∙Bγ)。