Skip to content

Commit

Permalink
Fix accept propagation error
Browse files Browse the repository at this point in the history
  • Loading branch information
rollrat authored May 18, 2019
1 parent 74ca644 commit 50ab0fe
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion InhaCC/InhaCC/cc/ScannerGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,26 @@ private bool opt_nfa(diagram dia)
tn.transition.ForEach(x => q.Enqueue(x.Item2));
}

// Accept Backpropagation
var check2 = new List<bool>(dia.count_of_vertex);
check2.AddRange(Enumerable.Repeat(false, dia.count_of_vertex));
var acc_nodes = new Queue<int>();
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;
}

Expand Down Expand Up @@ -984,4 +1004,4 @@ public Tuple<string, string, int, int> Lookahead()
return result;
}
}
}
}

0 comments on commit 50ab0fe

Please sign in to comment.