Example #1
0
        // Fill FIRST set for the chain of tokens.
        // Returns true if anything was added, false otherwise.
        private bool InternalAddFirsts(IEnumerable <int> chain, MutableIntSet result)
        {
            bool changed = false;

            bool nullable = true;

            foreach (int item in chain)
            {
                bool itemNullable = false;
                foreach (var f in firsts[item].ToArray())
                {
                    if (f == PredefinedTokens.Epsilon)
                    {
                        itemNullable = true; // current part is nullable
                        continue;
                    }

                    if (!result.Contains(f))
                    {
                        result.Add(f);
                        changed = true;
                    }
                }

                if (!itemNullable)
                {
                    nullable = false;
                    break;
                }
            }

            if (nullable && !result.Contains(PredefinedTokens.Epsilon))
            {
                result.Add(PredefinedTokens.Epsilon);
                changed = true;
            }

            return(changed);
        }
        public void set_has_correct_content_after_adding_value(IntSet set, int value)
        {
            MutableIntSet editedSet = set.EditCopy();

            Assert.AreEqual(set.Contains(value), editedSet.Contains(value));
            editedSet.Add(value);
            Assert.IsTrue(editedSet.Contains(value));

            Assert.IsTrue(editedSet.Contains(value));
            Assert.IsTrue(set.Union(IntSet.Of(value)).SetEquals(editedSet));
            IntSet result = editedSet.CompleteAndDestroy();

            Assert.IsTrue(result.Contains(value));
            Assert.IsTrue(set.IsSubsetOf(result));
            Assert.IsTrue(set.Union(IntSet.Of(value)).SetEquals(result));
        }