http://www.larc.usp.br/~pbarreto/LR.pdf
1: for every nonterminal C do
2: Compute all nonterminals A satisfying C →rm∗ A...
3: Compute all nonterminals B satisfying C →rm∗ B
4: end for
5: | Build relation inherits ctx between pairs of nonterminals:
6: for every production (A→Cα)∈P such that C ≠ A do
7: for every nonterminal B such that C →rm∗ B... do
8: Set the relation (A, B) inherits ctx(C, B)
9: end for
10:end for
11:| Compute ctx 0 (A, B):
12:Set ctx 0 (A, B) ← ∅
13:for all pairs (A, B) present in the inherits ctx relation do
14: for all α such that (A→Cα)∈P and C→rm∗ B do
15: Union FIRST (α) into ctx 0 (A, B)
16: end for
17:end for
18:Compute ctx(A, B) from ctx 0 (A, B) by taking the transitive closure of inherits ctx
19:| Compute the lookahead sets on demand during parser generation:
20:for each item [A→α·Xγ,u] in the state being generated where X is a nonterminal do
21: for each production N→Yβ of each nonterminal N such that X→rm∗ N... do
22: Let v←ctx(X,N)⊕FIRST(γu)
23: Merge into the successor state all items of form [N→Y·β,v]
24: end for
25:end for
Отредактировано Лис (2017-09-11 12:51:51)