private DFA.StateCollection CreateDFAStates(CGTContent content) { symbols = CreateSymbols(content); DFA.StateCollection states = new DFA.StateCollection(); foreach (DFAStateRecord stateRecord in content.DFAStateTable) { DFA.State state; if (stateRecord.AcceptState) { Symbol symbol = symbols[stateRecord.AcceptIndex]; state = new DFA.EndState(stateRecord.Index, (SymbolTerminal)symbol); //todo: type checking (exception?) } else { state = new DFA.State(stateRecord.Index); } states.Add(state); } foreach (DFAStateRecord stateRecord in content.DFAStateTable) { foreach (EdgeSubRecord edgeRecord in stateRecord.EdgeSubRecords) { DFA.State source = states[stateRecord.Index]; DFA.State target = states[edgeRecord.TargetIndex]; CharacterSetRecord charsetRec = content.CharacterSetTable[edgeRecord.CharacterSetIndex]; DFA.Transition transition = new DFA.Transition(target, charsetRec.Characters); source.Transitions.Add(transition); } } return(states); }
/// <summary> /// Creates a new tokenizer. Useful if for some reason /// you don't want a full LALR parser, but are just interested in a tokenizer. /// </summary> /// <returns></returns> public StringTokenizer CreateNewTokenizer() { DFA.State startState = dfaStates[content.InitialStates.DFA]; DFA.DFA dfa = new DFA.DFA(dfaStates, startState); return(new StringTokenizer(dfa)); }