/// <summary> /// 获取操作数 /// </summary> private BitArray GetOperator(string expression) { Regex reg = new Regex(@"\(\S+\)"); Match match = reg.Match(expression); string resultExpression = match.Value.Substring(1); resultExpression = resultExpression.Substring(0, resultExpression.Length - 1); return(ExpressionParser.ParseExpression(resultExpression)); }
public override BitArray Handle(string expression) { expression = expression.Trim(); // 左结合,因此先从最右开始 string op1 = expression.Substring(0, expression.LastIndexOf('+')).Trim(); string op2 = expression.Substring(expression.LastIndexOf('+') + 1).Trim(); // 将左边的表达式和右边的表达式交给解释器处理 BitArray result1 = ExpressionParser.ParseExpression(op1); BitArray result2 = ExpressionParser.ParseExpression(op2); return(result1.Xor(result2)); }
public override BitArray Handle(string expression) { expression = expression.Trim(); // 进行变量的绑定,因为变量可能是数组形式 string variableKey = expression.Substring(0, expression.IndexOf('=')).Trim(); variableKey = BindingVariable(variableKey); // 进行赋值运算符右边表达式的计算 string variableValue = expression.Substring(expression.IndexOf('=') + 1).Trim(); BitArray result = ExpressionParser.ParseExpression(variableValue); // 更新并返回变量的数值 Parser.VariableStorage.AddVariable(variableKey, result); return(result); }