Пример #1
0
        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;
 }
Пример #3
0
 public EndOfSubExpr(ExprPartsMemory memory)
 {
     this.memory = memory;
 }
Пример #4
0
 public NonPrefixOperator(ExprPartsMemory memory, char op)
 {
     this.memory = memory;
     this.memory.AddLast(SupportedOperators.OperatorsTable[op]);
 }
Пример #5
0
 public Number(ExprPartsMemory memory, string head)
 {
     this.memory            = memory;
     currentExprPartBuilder = new StringBuilder(head);
 }
Пример #6
0
 // 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());
 }