ex-ex-01-math-interpreter/MathInterpreter/Core/ExpressionScanner.cs
github-classroom[bot] 4b1294b32d
Initial commit
2025-06-03 15:18:01 +00:00

47 lines
2.1 KiB
C#

using System;
namespace MathInterpreter.Core;
/// <summary>
/// Provides utility methods for scanning character streams for certain parts of a maths expression
/// </summary>
public static class ExpressionScanner
{
/// <summary>
/// Scans the given expression for an operator (+, -, *, /)
/// </summary>
/// <param name="expression">Expression to process</param>
/// <returns>A scan result containing the operator found and the remaining part of the expression</returns>
/// <exception cref="OperatorException">Thrown if none or an unknown operator is found</exception>
public static ScanResult<Operator> ScanOperator(ReadOnlySpan<char> expression)
{
// TODO
throw new NotImplementedException();
}
/// <summary>
/// Scans the given expression for an operand which is a number which have to have an integral
/// part and may have a fractional part. It may also have a sign (+, -) in front of it.
/// </summary>
/// <param name="expression">Expression to process</param>
/// <returns>A scan result containing the parsed number and the remaining part expression</returns>
/// <exception cref="ExpressionFormatException">Thrown if a problem with the format of the number is found</exception>
public static ScanResult<double> ScanOperand(ReadOnlySpan<char> expression)
{
// TODO
throw new NotImplementedException();
}
/// <summary>
/// Scans the given expression for a whole number which may have a sign (+, -) in front of it
/// </summary>
/// <param name="expression">Expression to process</param>
/// <param name="allowSign">Flag indicating if a pre-fix sign (+, -) is allowed or not</param>
/// <returns>A scan result containing the parsed number and the remaining part expression</returns>
/// <exception cref="NumberFormatException">Thrown if no or an invalid number is found</exception>
public static ScanResult<int> ScanNumber(ReadOnlySpan<char> expression, bool allowSign)
{
// TODO
throw new NotImplementedException();
}
}