public static bool Scan(this IDfaSimulation dfa, int[] input, out int action) { int state = dfa.Start; int?acceptingState = null; foreach (var item in input) { if (!dfa.TryNext(state, item, out state)) { break; } if (dfa.IsAccepting(state)) { acceptingState = state; } } if (!acceptingState.HasValue) { action = -1; return(false); } var optAction = dfa.GetAction(acceptingState.Value); action = optAction.GetValueOrDefault(-1); return(true); }
private void CreateDfa() { var dfa = new RegularToDfaAlgorithm(regularTree); this.simulation = new DfaSimulation(dfa.Data); this.serialization = new DfaSerialization(dfa.Data); // DEBUG: Console.WriteLine(dfa); }
public static bool Match(this IDfaSimulation dfa, IEnumerable <int> input) { int state = dfa.Start; foreach (var item in input) { if (!dfa.TryNext(state, item, out state)) { return(false); } } return(dfa.IsAccepting(state)); }
public DfaSimulationLexer(TextReader textSource, ScannerDescriptor descriptor) { this.text = textSource.ReadToEnd(); this.descriptor = descriptor; var root = descriptor.MakeAst(); var regTree = new RegularTree(root); var algorithm = new RegularToDfaAlgorithm(regTree); this.dfa = new DfaSimulation(algorithm.Data); int count = descriptor.Matchers.Count; this.tokenFactories = new TokenFactoryDelegate[count]; for (int i = 0; i != count; ++i) { if (descriptor.Matchers[i].Outcome != null) { tokenFactories[i] = BuildTokenFactory(descriptor.Matchers[i]); } } }
public static bool MatchBeginning(this IDfaSimulation dfa, int[] input) { int action; return(dfa.Scan(input, out action)); }