Пример #1
0
        public void RegisterState(TdfaState state)
        {
            if (!state.IsAccepting)
            {
                return;
            }

            var orderedActions = state.Actions;

            var stateTokenProducers =
                from act in orderedActions
                select actionToTokenProducer[act];

            var stateTokenProducer = TokenProducerInfo.Combine(tokenSetType, stateTokenProducers);

            switch (stateTokenProducer.PossibleTokens.Count)
            {
            case 0:
                state.EnvelopeId = -1;
                break;

            case 1:
                state.EnvelopeId = stateTokenProducer.PossibleTokens.First();
                break;

            default:
                stateTokenProducer.State    = state;
                stateToTokenProducer[state] = stateTokenProducer;
                break;
            }

            state.Actions.Clear();
            state.Actions.AddRange(stateTokenProducer.RealActions);
            state.Actions.Sort();
        }
Пример #2
0
 public bool Equals(TokenProducerInfo other)
 {
     return(other != null &&
            MainTokenId == other.MainTokenId &&
            PossibleTokens.SetEquals(other.PossibleTokens) &&
            RealActions.SetEquals(other.RealActions));
 }
Пример #3
0
        public static TokenProducerInfo Combine(IntSetType tokenSetType, IEnumerable <TokenProducerInfo> items)
        {
            switch (items.Count())
            {
            case 0: return
                    (new TokenProducerInfo
                {
                    Disambiguation = Disambiguation.Exclusive,
                    RealActions = SparseIntSetType.Instance.Empty,
                    PossibleTokens = tokenSetType.Empty,
                    MainTokenId = -1,
                });

            case 1: return(items.First());
            }

            TokenProducerInfo result = null;

            foreach (var item in items)
            {
                if (item.Disambiguation == Disambiguation.Exclusive)
                {
                    if (result == null)
                    {
                        result = item;
                    }
                }
            }

            if (result == null)
            {
                result = new TokenProducerInfo {
                    Disambiguation = Disambiguation.Exclusive
                };
                int mainToken   = PredefinedTokens.NoToken;
                var allPossible = tokenSetType.Mutable();
                var allActions  = SparseIntSetType.Instance.Mutable();

                foreach (var item in items)
                {
                    if (mainToken != PredefinedTokens.NoToken && item.MainTokenId != PredefinedTokens.NoToken)
                    {
                        mainToken = item.MainTokenId;
                    }

                    allPossible.AddAll(item.PossibleTokens);
                    allActions.AddAll(item.RealActions);
                }

                result.MainTokenId    = mainToken;
                result.RealActions    = allActions.CompleteAndDestroy();
                result.PossibleTokens = allPossible.CompleteAndDestroy();
            }

            return(result);
        }
Пример #4
0
        public static TokenProducerInfo Combine(IntSetType tokenSetType, IEnumerable<TokenProducerInfo> items)
        {
            switch (items.Count())
            {
                case 0: return
                        new TokenProducerInfo
                        {
                            Disambiguation = Disambiguation.Exclusive,
                            RealActions = SparseIntSetType.Instance.Empty,
                            PossibleTokens = tokenSetType.Empty,
                            MainTokenId = -1,
                        };
                case 1: return items.First();
            }

            TokenProducerInfo result = null;

            foreach (var item in items)
            {
                if (item.Disambiguation == Disambiguation.Exclusive)
                {
                    if (result == null)
                    {
                        result = item;
                    }
                }
            }

            if (result == null)
            {
                result = new TokenProducerInfo { Disambiguation = Disambiguation.Exclusive };
                int mainToken = PredefinedTokens.NoToken;
                var allPossible = tokenSetType.Mutable();
                var allActions = SparseIntSetType.Instance.Mutable();

                foreach (var item in items)
                {
                    if (mainToken != PredefinedTokens.NoToken && item.MainTokenId != PredefinedTokens.NoToken)
                    {
                        mainToken = item.MainTokenId;
                    }

                    allPossible.AddAll(item.PossibleTokens);
                    allActions.AddAll(item.RealActions);
                }

                result.MainTokenId = mainToken;
                result.RealActions = allActions.CompleteAndDestroy();
                result.PossibleTokens = allPossible.CompleteAndDestroy();
            }

            return result;
        }
Пример #5
0
 public bool Equals(TokenProducerInfo other)
 {
     return other != null
         && MainTokenId == other.MainTokenId
         && PossibleTokens.SetEquals(other.PossibleTokens)
         && RealActions.SetEquals(other.RealActions);
 }