protected override ParsedSyntax Syntax(ParsedSyntax left, IToken token, ParsedSyntax right) { if(left == null || right == null) return base.Syntax(left, token, right); return new PowerSyntax(this, left, token, right); }
string SmartDump(ParsedSyntax x, bool isWatched) { var result = x.SmartDump(this); if(isWatched) result += ("\n" + x.Dump() + "\n").Indent(3); return result; }
string ISmartDumpToken.SmartDumpListDelim(ParsedSyntax parsedSyntax, bool isFirst) { if(parsedSyntax.IsNegative) return (isFirst ? "" : " ") + "- "; return isFirst ? "" : " + "; }
protected override ParsedSyntax Syntax(ParsedSyntax left, IToken token, ParsedSyntax right) { if(left == null || right == null) return base.Syntax(left, token, right); return new GreatesCommonDenominatorSyntax(this, left, token, right); }
protected override ParsedSyntax Syntax(ParsedSyntax left, IToken token, ParsedSyntax right) { Tracer.Assert(left != null); Tracer.Assert(right != null); return left.Associative(this, token, right); }
protected override ParsedSyntax Syntax(ParsedSyntax left, IToken token, ParsedSyntax right) { if(left == null || right == null) return base.Syntax(left, token, right); return left.Equal(token, right); }
protected override ParsedSyntax Syntax(ParsedSyntax left, IToken token, ParsedSyntax right) { if(left != null || right != null) return base.Syntax(left, token, right); return new IntegerSyntax(token); }
protected override ParsedSyntax Syntax(ParsedSyntax left, IToken token, ParsedSyntax right) { if(left == null) return right ?? TrueSyntax.Instance; if(right == null) return left; return left.Associative(this, token, right); }
protected override ParsedSyntax IsolateClause (string variable, ParsedSyntax left, ParsedSyntax right) { if(!left.Variables.Contains(variable)) { if(right.Variables.Contains(variable)) return IsolateClause(variable, right, left); return null; } if(right.Variables.Contains(variable)) { NotImplementedMethod(variable, left, right); return null; } return left.IsolateFromEquation(variable, right); }
string ISmartDumpToken.SmartDumpListDelim(ParsedSyntax parsedSyntax, bool isFirst) { NotImplementedMethod(parsedSyntax, isFirst); return null; }
protected virtual ParsedSyntax IsolateClause (string variable, ParsedSyntax left, ParsedSyntax right) => null;
ParsedSyntax IPair.IsolateClause(string variable, ParsedSyntax left, ParsedSyntax right) => IsolateClause(variable, left, right);
ParsedSyntax IPair.Pair(ParsedSyntax left, ParsedSyntax right) => Syntax(left, null, right);
internal override ParsedSyntax CombineForPlus(ParsedSyntax other) => other.CombineForPlus(this);
string IPair.SmartDump(ParsedSyntax left, ParsedSyntax right) => SmartDump(left, right);
ParsedSyntax IAssociative.Combine(ParsedSyntax left, ParsedSyntax right) => null;
public GreatesCommonDenominatorSyntax (IPair @operator, ParsedSyntax left, IToken token, ParsedSyntax right) : base(@operator, left, token, right) { }
ParsedSyntax IAssociative.Combine(ParsedSyntax left, ParsedSyntax right) => left.CombineForPlus(right);
static IEnumerable<KeyValuePair<string, ParsedSyntax>> GetDefinitions (ParsedSyntax parsedSyntax) { return parsedSyntax.Variables.Select(parsedSyntax.GetDefinition); }
Set<ParsedSyntax> IStrategy.Apply(ParsedSyntax parsedSyntax) { if(parsedSyntax.Variables.Count() > _variableCount) return Set<ParsedSyntax>.Empty; return parsedSyntax.Replace(_definitions) - parsedSyntax; }
bool IAssociative.IsEmpty(ParsedSyntax parsedSyntax) { var numberSyntax = parsedSyntax as NumberSyntax; return numberSyntax != null && numberSyntax.Value == 0; }
public PowerSyntax(IPair @operator, ParsedSyntax left, IToken token, ParsedSyntax right) : base(@operator, left, token, right) {}
string SmartDump(ParsedSyntax left, ParsedSyntax right) => "(" + left.SmartDump(this) + " " + Id + " " + right.SmartDump(this) + ")";
bool IAssociative.IsEmpty(ParsedSyntax parsedSyntax) => parsedSyntax is TrueSyntax;
public LeftParenthesisSyntax(int level, IToken token, ParsedSyntax right) : base(token) { Level = level; Right = right; }
string ISmartDumpToken.SmartDumpListDelim(ParsedSyntax parsedSyntax, bool isFirst) => isFirst ? "" : " & ";
protected override ParsedSyntax Syntax(ParsedSyntax left, IToken token, ParsedSyntax right) { Tracer.Assert(left == null); return new LeftParenthesisSyntax(_level, token, right); }
internal override ParsedSyntax CombineForPlus(ParsedSyntax other, BigRational otherValue) => other.CombineForPlus(this, otherValue);