示例#1
0
        private Node ParseMultiplyDivide()
        {
            Node lhs = ParseUnary();

            while (true)
            {
                Func <float, float, float> op = null;
                if (this.tokenizer.currentToken == Tokenizer.Token.Multiply)
                {
                    op = (a, b) => a * b;
                }
                else if (this.tokenizer.currentToken == Tokenizer.Token.Divide)
                {
                    op = (a, b) => a / b;
                }

                if (op == null)
                {
                    return(lhs);
                }

                this.tokenizer.NextToken();
                Node rhs = this.ParseUnary();
                lhs = new NodeBinary(lhs, rhs, op);
            }
        }
示例#2
0
        private Node ParseAddSubtract()
        {
            Node lhs = ParseMultiplyDivide();

            while (true)
            {
                Func <float, float, float> op = null;
                if (this.tokenizer.currentToken == Tokenizer.Token.Add)
                {
                    op = (a, b) => a + b;
                }
                else if (this.tokenizer.currentToken == Tokenizer.Token.Subtract)
                {
                    op = (a, b) => a - b;
                }

                if (op == null)
                {
                    return(lhs);
                }
                this.tokenizer.NextToken();

                Node rhs = ParseMultiplyDivide();
                lhs = new NodeBinary(lhs, rhs, op);
            }
        }