【tmp】LR(0)

来源:互联网 发布:sql server 2008下载 编辑:程序博客网 时间:2024/06/06 07:36
stack = []push ($) //$: end of filepush (1) // 1: initial statewhile (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γ)
0 0