protected override bool IsPossibleNextPart(PartRuleType nextType) { if (IsOptimalNextPart(nextType)) { return(true); } return(nextType == PartRuleType.AddSub || nextType == PartRuleType.OneValueFunction); }
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); }
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(); } } }
protected abstract bool WasAbleToChangeIfNecessary(Parts parts, int thisIndex, PartRuleType nextType);
protected abstract bool IsOptimalNextPart(PartRuleType nextType);
protected abstract bool IsPossibleNextPart(PartRuleType nextType);
protected override bool IsOptimalNextPart(PartRuleType nextType) { return(nextType == PartRuleType.AddSub || nextType == PartRuleType.End || nextType == PartRuleType.MultDiv || nextType == PartRuleType.TwoValueFunction); }
protected override bool IsOptimalNextPart(PartRuleType nextType) { return(nextType == PartRuleType.OneValueFunction || nextType == PartRuleType.Start || nextType == PartRuleType.Value); }
protected override bool WasAbleToChangeIfNecessary(Parts parts, int thisIndex, PartRuleType nextType) { if (nextType == PartRuleType.AddSub) { ((PartAddSub)parts[thisIndex + 1]).ChangeToPartSignIfSub(parts); return(true); } return(false); }
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)); }