Exemplo n.º 1
0
        public IEnumerable <RawMultiplier> Iterator()
        {
            RawMultiplier output = null;

            foreach (char c in this.rawExpression.rawString)
            {
                switch (this.state)
                {
                case ParseStates.Start:
                    this.HandleStart(c);
                    break;

                case ParseStates.WaitSymbols:
                    this.HandleWaitSymbols(c);
                    break;

                case ParseStates.WaitOperand:
                    output = this.HandleWaitOperand(c);
                    break;

                case ParseStates.EscapeSymbols:
                    this.HandleEscapeSymbols(c);
                    break;
                }

                if (output != null)
                {
                    yield return(output);

                    output = null;
                }

                this.index++;
                this.globalIndex++;
            }

            yield return(this.Finalize());

            this.reset();
        }
Exemplo n.º 2
0
        private RawMultiplier HandleWaitOperand(char c)
        {
            if (c == '+' || c == '-')
            {
                string rawBlockString = this.rawExpression
                                        .rawString.Substring(this.blockOffset, index - this.blockOffset);
                RawMultiplier output = new RawMultiplier(this.blockOffset, rawBlockString, this.coeff);
                // define coefficent
                this.coeff = (c == '-') ? -1 : 1;
                this.state = ParseStates.WaitSymbols;

                return(output);
            }
            else
            {
                if (c == '(')
                {
                    this.state = ParseStates.EscapeSymbols;
                }
            }

            return(null);
        }
Exemplo n.º 3
0
 public RawMultiplierParser(RawMultiplier rawMultiplier)
 {
     this.rawMultiplier = rawMultiplier;
 }
Exemplo n.º 4
0
        public void Parse(RawMultiplier rawMultiplier)
        {
            RawMultiplierParser parser = new RawMultiplierParser(rawMultiplier);

            this.expressions = parser.Parse();
        }
Exemplo n.º 5
0
 public Multiplier(RawMultiplier rawMultiplier)
 {
     this.rawMultiplier = rawMultiplier;
     this.coeff         = rawMultiplier.coeff;
     this.Parse(rawMultiplier);
 }