Exemple #1
0
        protected override bool IsPossibleNextPart(PartRuleType nextType)
        {
            if (IsOptimalNextPart(nextType))
            {
                return(true);
            }

            return(nextType == PartRuleType.AddSub || nextType == PartRuleType.OneValueFunction);
        }
Exemple #2
0
        protected override bool WasAbleToChangeIfNecessary(Parts parts,
                                                           int thisIndex, PartRuleType nextType)
        {
            if (nextType == PartRuleType.Start || nextType == PartRuleType.Value ||
                nextType == PartRuleType.OneValueFunction)
            {
                parts.Insert(thisIndex + 1, new PartMult());
                return(true);
            }

            return(false);
        }
Exemple #3
0
        public void CheckIfPossibleNextPart(Parts parts)
        {
            while (true)
            {
                int          thisIndex = parts.ExtendedIndexOf(this);
                PartRuleType nextType  = parts[thisIndex + 1].GetRuleType();

                if (IsOptimalNextPart(nextType))
                {
                    return;
                }

                if (!IsPossibleNextPart(nextType) || !WasAbleToChangeIfNecessary(parts, thisIndex, nextType))
                {
                    throw new ArgumentException();
                }
            }
        }
Exemple #4
0
 protected abstract bool WasAbleToChangeIfNecessary(Parts parts, int thisIndex, PartRuleType nextType);
Exemple #5
0
 protected abstract bool IsOptimalNextPart(PartRuleType nextType);
Exemple #6
0
 protected abstract bool IsPossibleNextPart(PartRuleType nextType);
Exemple #7
0
 protected override bool IsOptimalNextPart(PartRuleType nextType)
 {
     return(nextType == PartRuleType.AddSub || nextType == PartRuleType.End ||
            nextType == PartRuleType.MultDiv || nextType == PartRuleType.TwoValueFunction);
 }
Exemple #8
0
 protected override bool IsOptimalNextPart(PartRuleType nextType)
 {
     return(nextType == PartRuleType.OneValueFunction ||
            nextType == PartRuleType.Start || nextType == PartRuleType.Value);
 }
Exemple #9
0
        protected override bool WasAbleToChangeIfNecessary(Parts parts, int thisIndex, PartRuleType nextType)
        {
            if (nextType == PartRuleType.AddSub)
            {
                ((PartAddSub)parts[thisIndex + 1]).ChangeToPartSignIfSub(parts);

                return(true);
            }

            return(false);
        }
Exemple #10
0
        protected override bool WasAbleToChangeIfNecessary(Parts parts, int thisIndex, PartRuleType nextType)
        {
            Part nextPart = parts[thisIndex + 1];

            if (!(nextPart is PartAddSub))
            {
                return(false);
            }

            ((PartAddSub)nextPart).ChangeToPartSignIfSub(parts);

            return(true);
        }
 protected override bool IsPossibleNextPart(PartRuleType nextType)
 {
     return(nextType == PartRuleType.AddSub || IsOptimalNextPart(nextType));
 }