Skip to content

Commit

Permalink
#236 - Rework parser (remove RPN)
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Aug 2, 2019
1 parent c3ae1e2 commit 47d3be6
Show file tree
Hide file tree
Showing 69 changed files with 1,211 additions and 907 deletions.
20 changes: 10 additions & 10 deletions xFunc.Benchmark/Benchmarks/ParserBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public void Setup()
.Number(100.1)
.Operation(Operations.Addition)
.OpenBracket()
.Function(Functions.Sine, 1)
.Function(Functions.Sine)
.OpenBracket()
.Function(Functions.Cosine, 1)
.Function(Functions.Cosine)
.OpenBracket()
.Function(Functions.Tangent, 1)
.Function(Functions.Tangent)
.OpenBracket()
.Function(Functions.Cotangent, 1)
.Function(Functions.Cotangent)
.OpenBracket()
.VariableX()
.CloseBracket()
Expand All @@ -59,7 +59,7 @@ public void Setup()
.CloseBracket()
.Operation(Operations.Subtraction)
.OpenBracket()
.Function(Functions.Cosine, 1)
.Function(Functions.Cosine)
.OpenBracket()
.VariableY()
.CloseBracket()
Expand All @@ -78,18 +78,18 @@ public void Setup()
.CloseBracket()
.Operation(Operations.Addition)
.OpenBracket()
.Function(Functions.Determinant, 1)
.Function(Functions.Determinant)
.OpenBracket()
.Function(Functions.Matrix, 2)
.Function(Functions.Matrix)
.OpenBrace()
.Function(Functions.Vector, 2)
.Function(Functions.Vector)
.OpenBrace()
.Number(1)
.Comma()
.Number(2)
.CloseBrace()
.Comma()
.Function(Functions.Vector, 2)
.Function(Functions.Vector)
.OpenBrace()
.Number(3)
.Comma()
Expand All @@ -98,7 +98,7 @@ public void Setup()
.CloseBrace()
.CloseBracket()
.Operation(Operations.Multiplication)
.Function(Functions.Log, 2)
.Function(Functions.Log)
.OpenBracket()
.Number(2)
.Comma()
Expand Down
1 change: 1 addition & 0 deletions xFunc.DotnetTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using xFunc.Maths.Analyzers.TypeAnalyzers;
using xFunc.Maths.Expressions;
using xFunc.Maths.Expressions.Collections;
using xFunc.Maths.Tokenization;

namespace xFunc.DotnetTool
{
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public Builder Log(IExpression @base)
{
CheckCurrentExpression();

current = new Log(current, @base);
current = new Log(@base, current);

return this;
}
Expand Down
382 changes: 139 additions & 243 deletions xFunc.Maths/ExpressionFactory.cs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public class Add : BinaryExpression
/// <seealso cref="IExpression"/>
public Add(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="Add"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public Add((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down
10 changes: 1 addition & 9 deletions xFunc.Maths/Expressions/BinaryExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace xFunc.Maths.Expressions
/// <summary>
/// The base class for binary operations.
/// </summary>
public abstract class BinaryExpression : IFunctionExpression
public abstract class BinaryExpression : IExpression
{

/// <summary>
Expand Down Expand Up @@ -197,14 +197,6 @@ public virtual IExpression Right
/// </summary>
public virtual IExpression Parent { get; set; }

/// <summary>
/// Gets the count of parameters.
/// </summary>
/// <value>
/// The count of parameters.
/// </value>
public virtual int ParametersCount => 2;

}

}
17 changes: 8 additions & 9 deletions xFunc.Maths/Expressions/Define.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace xFunc.Maths.Expressions
/// <summary>
/// Represents the Define operation.
/// </summary>
public class Define : IFunctionExpression
public class Define : IExpression
{

private IExpression key;
Expand All @@ -40,6 +40,13 @@ public Define(IExpression key, IExpression value)
this.Value = value;
}

/// <summary>
/// Initializes a new instance of the <see cref="Define"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public Define((IExpression key, IExpression value) arguments) : this(arguments.key, arguments.value) { }

/// <summary>
/// Determines whether the specified <see cref="Object" />, is equal to this instance.
/// </summary>
Expand Down Expand Up @@ -168,14 +175,6 @@ public IExpression Clone()
/// </summary>
public IExpression Parent { get; set; }

/// <summary>
/// Gets the count of parameters.
/// </summary>
/// <value>
/// The count of parameters.
/// </value>
public int ParametersCount => 2;

/// <summary>
/// Gets or sets the key.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Expressions/DifferentParametersExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace xFunc.Maths.Expressions
/// <summary>
/// The base class for expressions with different number of parameters.
/// </summary>
public abstract class DifferentParametersExpression : IFunctionExpression
public abstract class DifferentParametersExpression : IExpression
{

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/Div.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public class Div : BinaryExpression
/// <param name="right">The second (right) operand.</param>
public Div(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="Div"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public Div((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Executes this expression.
/// </summary>
Expand Down
35 changes: 0 additions & 35 deletions xFunc.Maths/Expressions/IFunctionExpression.cs

This file was deleted.

13 changes: 10 additions & 3 deletions xFunc.Maths/Expressions/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ public class Log : BinaryExpression
/// <summary>
/// Initializes a new instance of the <see cref="Log"/> class.
/// </summary>
/// <param name="arg">The left operand.</param>
/// <param name="base">The right operand.</param>
/// <param name="arg">The left operand.</param>
/// <seealso cref="IExpression"/>
public Log(IExpression @base, IExpression arg) : base(@base, arg) { }

/// <summary>
/// Initializes a new instance of the <see cref="Log"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public Log(IExpression arg, IExpression @base) : base(@base, arg) { }
public Log((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
Expand Down Expand Up @@ -90,7 +97,7 @@ public override TResult Analyze<TResult>(IAnalyzer<TResult> analyzer)
/// <returns>Returns the new instance of <see cref="IExpression"/> that is a clone of this instance.</returns>
public override IExpression Clone()
{
return new Log(m_right.Clone(), m_left.Clone());
return new Log(m_left.Clone(), m_right.Clone());
}

}
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/LogicalAndBitwise/And.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public class And : BinaryExpression
/// <param name="right">The right (second) operand.</param>
public And(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="And"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public And((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/LogicalAndBitwise/Equality.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public class Equality : BinaryExpression
/// <param name="right">The right (second) operand.</param>
public Equality(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="Equality"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public Equality((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/LogicalAndBitwise/Implication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public class Implication : BinaryExpression
/// <param name="right">The right (second) operand.</param>
public Implication(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="Implication"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public Implication((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/LogicalAndBitwise/NAnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public class NAnd : BinaryExpression
/// <seealso cref="IExpression"/>
public NAnd(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="NAnd"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public NAnd((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/LogicalAndBitwise/NOr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public class NOr : BinaryExpression
/// <param name="right">The right (second) operand.</param>
public NOr(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="NOr"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public NOr((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/LogicalAndBitwise/Or.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public class Or : BinaryExpression
/// <param name="right">The right (second) operand.</param>
public Or(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="Or"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public Or((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/LogicalAndBitwise/XOr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public class XOr : BinaryExpression
/// <seealso cref="IExpression"/>
public XOr(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="XOr"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public XOr((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/Matrices/CrossProduct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public class CrossProduct : BinaryExpression
/// <param name="right">The right (second) operand.</param>
public CrossProduct(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="CrossProduct"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public CrossProduct((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/Matrices/DotProduct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public class DotProduct : BinaryExpression
/// <param name="right">The right (second) operand.</param>
public DotProduct(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="DotProduct"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public DotProduct((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public class Mod : BinaryExpression
/// <param name="right">The right (second) operand.</param>
public Mod(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="Mod"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public Mod((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions xFunc.Maths/Expressions/Mul.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public class Mul : BinaryExpression
/// <param name="right">The second (right) operand.</param>
public Mul(IExpression left, IExpression right) : base(left, right) { }

/// <summary>
/// Initializes a new instance of the <see cref="Mul"/> class.
/// </summary>
/// <param name="arguments">The tuple of arguments.</param>
/// <seealso cref="IExpression"/>
public Mul((IExpression left, IExpression right) arguments) : base(arguments.left, arguments.right) { }

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
Expand Down

0 comments on commit 47d3be6

Please sign in to comment.