Skip to content

Commit 74ca644

Browse files
authored
Fix accept propagation error
1 parent d383c0f commit 74ca644

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

ScannerGenerator.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,26 @@ private bool opt_nfa(diagram dia)
470470
tn.transition.ForEach(x => q.Enqueue(x.Item2));
471471
}
472472

473+
// Accept Backpropagation
474+
var check2 = new List<bool>(dia.count_of_vertex);
475+
check2.AddRange(Enumerable.Repeat(false, dia.count_of_vertex));
476+
var acc_nodes = new Queue<int>();
477+
dia.nodes.Where(x => x.is_acceptable).ToList().ForEach(d => acc_nodes.Enqueue(d.index));
478+
// recalculate inverse transtion
479+
inverse_transition = get_inverse_transtition(dia);
480+
481+
while (acc_nodes.Count != 0)
482+
{
483+
var top = acc_nodes.Dequeue();
484+
if (check2[top]) continue;
485+
check2[top] = true;
486+
dia.nodes[top].is_acceptable = true;
487+
if (inverse_transition.ContainsKey(top))
488+
foreach (var inv in inverse_transition[top])
489+
if (dia.nodes[inv].transition.Where(x => x.Item2.index == top).First().Item1 == 0)
490+
acc_nodes.Enqueue(inv);
491+
}
492+
473493
return opt;
474494
}
475495

@@ -984,4 +1004,4 @@ public Tuple<string, string, int, int> Lookahead()
9841004
return result;
9851005
}
9861006
}
987-
}
1007+
}

0 commit comments

Comments
 (0)