Node ParseMultiplyDivide() { var lhs = ParseUnary(); while (true) { Func <double, double, double> op = null; if (_tokenizer.Token == Token.Multiply) { op = (a, b) => a * b; } else if (_tokenizer.Token == Token.Divide) { op = (a, b) => a / b; } if (op == null) { return(lhs); } _tokenizer.NextToken(); var rhs = ParseUnary(); lhs = new NodeBinary(lhs, rhs, op); } }
Node ParseAddSubtract() { var lhs = ParseMultiplyDivide(); while (true) { Func <double, double, double> op = null; if (_tokenizer.Token == Token.Add) { op = (a, b) => a + b; } else if (_tokenizer.Token == Token.Subtract) { op = (a, b) => a - b; } if (op == null) { return(lhs); // no } _tokenizer.NextToken(); var rhs = ParseMultiplyDivide(); lhs = new NodeBinary(lhs, rhs, op); } }