public static NumberExprPart ConsumeInput(Queue <char> input) { ExprPartsMemory.RecursionLevel++; if (!input.TryDequeue(out var c)) { throw new UnexpectedEndOfInputException(); } if (c.IsOpeningBracket()) { var memory = new ExprPartsMemory(); memory.AddLast(ConsumeInput(input)); return(new EndOfSubExpr(memory).ConsumeInput(input)); } if (c.IsPartOfNumber()) { return(new Number(new ExprPartsMemory(), c.ToString()).ConsumeInput(input)); } if (c.IsPrefixOperator()) { return(new PrefixOperator(new ExprPartsMemory(), c).ConsumeInput(input)); } throw new InvalidCharacterSequenceException(c, ExprPartsMemory.InputLength - input.Count); }
public PrefixOperator(ExprPartsMemory memory, char op) { this.memory = memory; this.op = op; }
public EndOfSubExpr(ExprPartsMemory memory) { this.memory = memory; }
public NonPrefixOperator(ExprPartsMemory memory, char op) { this.memory = memory; this.memory.AddLast(SupportedOperators.OperatorsTable[op]); }
public Number(ExprPartsMemory memory, string head) { this.memory = memory; currentExprPartBuilder = new StringBuilder(head); }
// this exists only for better understanding of code, so we can clearly see the endpoint of the expr parsing public static NumberExprPart GetResult(ExprPartsMemory memory) { return(memory.GetResult()); }