Ejemplo n.º 1
0
 public bool Process(string input)
 {
     //
     Input.Clear();
     foreach (char c in input.Reverse())
     {
         Input.Push(c);
     }
     //
     Stack.Clear(); Stack.Push(startStack);
     //
     curCommand = new PACInput(startState, Input.Peek(), Stack.Peek());
     while (Stack.Count > 0)
     {
         if (logging)
         {
             Log();
         }
         if (processCommand())
         {
             return(false);
         }
     }
     return(Input.Count == 0 && finalStates.Contains(curCommand.state));
 }
Ejemplo n.º 2
0
        public bool FindCycle(out string cycle)
        {
            cycle = "";
            int         Q  = commands.Select((x) => x.Key.state).Distinct().Count();
            List <char> A0 = commands.Values.Aggregate((x, y) => new PACOutput("", x.stack + y.stack)).stack.ToArray().Distinct().ToList();

            A0.Remove('^');
            int A = A0.Count();
            int L = commands.Values.Select((x) => x.stack).Max((x) => x.Length);

            Console.WriteLine($"#Г = {A}");
            Console.WriteLine($"l = {L}");
            Console.WriteLine($"#Q = {Q}");
            int n3 = 0;

            if (A == 1)
            {
                n3 = Q * Q;
            }
            else
            {
                n3 = Q * ((int)Math.Pow(A, A * Q * L + 1) - A) / (A - 1);
            }
            var tickStates = from kv in commands
                             where kv.Key.input == '^'
                             select kv;

            foreach (var s in tickStates)
            {
                Input.Clear();
                Input.Push('^');
                //
                Stack.Clear(); Stack.Push(s.Key.stack);
                //
                curCommand = new PACInput(s.Key.state, Input.Peek(), Stack.Peek());
                int count = 0;
                while (Stack.Count > 0 && count < n3 + 1)
                {
                    if (processCommand())
                    {
                        break;
                    }
                    if (curCommand.input != '^')
                    {
                        break;
                    }
                    count++;
                }
                if (count == n3 + 1)
                {
                    cycle = $" {s.Key.state} {s.Key.input} {s.Key.stack} "; return(true);
                }
            }
            return(false);
        }