コード例 #1
0
 private static void AddStatesToPda(PDA <char, char> pda, XElement xmlPDA)
 {
     foreach (var node in xmlPDA.Elements().Where(el => el.Name.LocalName == XmlNames.Nodes).First().Elements().Where(el => el.Name.LocalName == XmlNames.InnerState))
     {
         pda.AddState(int.Parse(node.Attribute(XmlAttr.Id).Value), Boolean.Parse(node.Attribute(XmlAttr.IsFinal).Value));
     }
 }
コード例 #2
0
        private static int AddNewState(PDA <A, S> newPDA)
        {
            var newStateId = newPDA.States.Max(n => n.Key) + 1;

            newPDA.AddState(newStateId, false);
            return(newStateId);
        }
コード例 #3
0
 private static void AddStatesOfOriginalPDA(PDA <A, S> pda, PDA <A, S> newPDA, Func <int, int> transformer)
 {
     foreach (var state in pda.States)
     {
         newPDA.AddState(transformer(state.Key), false);
     }
 }
コード例 #4
0
        public PDA <A, S> Clone()
        {
            var res = new PDA <A, S>(AcceptanceCondition, true, FirstStackSymbol, InitialState.Final, AllStackSymbols.ToList());

            foreach (var state in States.Where(s => s.Key != initialStateId).ToList())
            {
                res.AddState(state.Key, state.Value.Final);
            }
            foreach (var state in States)
            {
                foreach (var t in state.Value.Transitions)
                {
                    res.AddTransition().From(t.Origin.Id).To(t.Target.Id).Read(t.SymbolIn).Pop(t.StackSymbolIn).Push(t.StackSymbolsWritten);
                }
            }
            return(res);
        }