diff --git a/InhaCC/InhaCC/cc/ScannerGenerator.cs b/InhaCC/InhaCC/cc/ScannerGenerator.cs index 50c3a1f..f2dd9e1 100644 --- a/InhaCC/InhaCC/cc/ScannerGenerator.cs +++ b/InhaCC/InhaCC/cc/ScannerGenerator.cs @@ -470,6 +470,26 @@ private bool opt_nfa(diagram dia) tn.transition.ForEach(x => q.Enqueue(x.Item2)); } + // Accept Backpropagation + var check2 = new List(dia.count_of_vertex); + check2.AddRange(Enumerable.Repeat(false, dia.count_of_vertex)); + var acc_nodes = new Queue(); + dia.nodes.Where(x => x.is_acceptable).ToList().ForEach(d => acc_nodes.Enqueue(d.index)); + // recalculate inverse transtion + inverse_transition = get_inverse_transtition(dia); + + while (acc_nodes.Count != 0) + { + var top = acc_nodes.Dequeue(); + if (check2[top]) continue; + check2[top] = true; + dia.nodes[top].is_acceptable = true; + if (inverse_transition.ContainsKey(top)) + foreach (var inv in inverse_transition[top]) + if (dia.nodes[inv].transition.Where(x => x.Item2.index == top).First().Item1 == 0) + acc_nodes.Enqueue(inv); + } + return opt; } @@ -984,4 +1004,4 @@ public Tuple Lookahead() return result; } } -} \ No newline at end of file +}