67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace MathInterpreter.Core;
|
|
|
|
/// <summary>
|
|
/// Represents a mathematical expression
|
|
/// </summary>
|
|
public sealed class MathExpression
|
|
{
|
|
// TODO
|
|
/*
|
|
private double? _leftOperand;
|
|
private Operator? _operator;
|
|
private double? _result;
|
|
private double? _rightOperand;
|
|
*/
|
|
|
|
/// <summary>
|
|
/// Creates a new instance of <see cref="MathExpression" /> from the provided expression string.
|
|
/// Validates the provided expression and throws an exception if it is invalid.
|
|
/// </summary>
|
|
/// <param name="expressionString">The expression as a string</param>
|
|
/// <exception cref="OperatorException">Thrown if a problem with the operator is found</exception>
|
|
/// <exception cref="ExpressionFormatException">Thrown if a problem with the expression format is found</exception>
|
|
/// <exception cref="NumberValueException">Thrown if a problem with the value of a number is found</exception>
|
|
public MathExpression(string expressionString)
|
|
{
|
|
ValidateAndParse(expressionString.Trim().AsSpan());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the calculated result of the expression
|
|
/// </summary>
|
|
/// <exception cref="UnreachableException">
|
|
/// Thrown if validation during construction did not guard against an unexpected, invalid expression
|
|
/// </exception>
|
|
public double Result
|
|
{
|
|
get
|
|
{
|
|
// TODO
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a string representation of the expression - this is not the originally provided string
|
|
/// but the cleaned up version
|
|
/// </summary>
|
|
/// <returns>String representation of the expression</returns>
|
|
/// <exception cref="UnreachableException">
|
|
/// Thrown if validation during construction did not guard against an unexpected, invalid expression
|
|
/// and left this instance in an invalid state
|
|
/// </exception>
|
|
public override string ToString()
|
|
{
|
|
// TODO
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private void ValidateAndParse(ReadOnlySpan<char> expression)
|
|
{
|
|
// TODO
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|