Ejemplo n.º 1
0
        public StackSymbolSequenceSet <S> ApplySymbolToStackSymbolSequenceSet(StackSymbolSequenceSet <S> stackSequenceSet, A symbol)
        {
            var res = stackSequenceSet.StackSequenceSet.Select(stackSequence =>
            {
                if (stackSequence.IsEpsilon())
                {
                    return(new StackSymbolSequenceSet <S>());
                }

                var first = stackSequence.StackSequence.First();
                var enterableTransitions = transitions.Where(t => t.CanBeEntered(symbol, first));

                Assertion.Assert(enterableTransitions.Count() <= 1, "in a determinised SDA, only one transition can be entered for a specific configuration");

                if (enterableTransitions.Count() == 0)
                {
                    return(new StackSymbolSequenceSet <S>());
                }

                var stackSymbolsSetWritten = enterableTransitions.First().StackSymbolsSetWritten;
                var remainingStackSequence = new StackSymbolSequence <S>(stackSequence.StackSequence.Skip(1).ToList());
                return(stackSymbolsSetWritten.Multiply(remainingStackSequence));
            });

            return(StackSymbolSequenceSet <S> .Flatten(res));
        }
Ejemplo n.º 2
0
 public DeterminisedSDATransition(A symbolIn, S stackSymbolIn, StackSymbolSequenceSet <S> stackSymbolsSetWritten)
 {
     Assertion.Assert(stackSymbolsSetWritten.StackSequenceSet.All(s => s.StackSequence.Length <= 2), "as a determinised SDA is in normal form, a transition may only push at most two symbols");
     SymbolIn               = symbolIn;
     StackSymbolIn          = stackSymbolIn;
     StackSymbolsSetWritten = stackSymbolsSetWritten;
 }
Ejemplo n.º 3
0
        public void AddTransition(A symbolIn, S stackSymbolIn, StackSymbolSequenceSet <S> stackSymbolsSetWritten)
        {
            Assertion.Assert(AllStackSymbols.Any(s => s.Equals(stackSymbolIn)), InvalidStackSymbolError);
            Assertion.Assert(stackSymbolsSetWritten.StackSequenceSet.All(s => s.StackSequence.All(symbol => AllStackSymbols.Any(t => t.Equals(symbol)))), InvalidStackSymbolError);
            Assertion.Assert(stackSymbolsSetWritten.StackSequenceSet.All(s => s.StackSequence.Length <= 2), "as a determinised SDA is in normal form, only two stack symbols can be pushed");

            Assertion.Assert(!transitions.Any(t => t.SymbolIn.Equals(symbolIn) && t.StackSymbolIn.Equals(stackSymbolIn)), "the new transition violates the determinism property of the determinised SDA");

            transitions.Add(new DeterminisedSDATransition <A, S>(symbolIn, stackSymbolIn, stackSymbolsSetWritten));
        }
Ejemplo n.º 4
0
 public StackSymbolSequenceSet <S> ApplyWordToStackSymbolSequenceSet(StackSymbolSequenceSet <S> stackSymbolSequenceSet, IEnumerable <A> word)
 {
     return(word.Aggregate(stackSymbolSequenceSet, (acc, symbol) => ApplySymbolToStackSymbolSequenceSet(acc, symbol)));
 }