コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Transition.cs プロジェクト: CSRedRat/pascalabcnet
		public int Add(Transition transition)
		{
			IEnumerator enumerator = transition.CharSet.GetEnumerator();
			while (enumerator.MoveNext())
			{
				char ch = (char)enumerator.Current;
				map.Add(ch, transition);
			}
			return list.Add(transition);
		}
コード例 #3
0
ファイル: Reader.cs プロジェクト: langpavel/LPS-old
        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;
        }