private void Atom(out object result) { ComputeEngineTokenType computeEngineTokenType = this.tokType; if (computeEngineTokenType != ComputeEngineTokenType.TkNumber) { if (computeEngineTokenType != ComputeEngineTokenType.TkString) { result = null; throw new ComputeEngineParserException("计算表达式语法错误!"); } result = this.token; this.GetToken(); } else { try { result = double.Parse(this.token); } catch (FormatException) { throw new ComputeEngineParserException("计算表达式语法错误!"); } this.GetToken(); } }
private void ReplaceVariable() { string tokenUpp = this.token.ToUpper(); bool flag = this.InnerVariables.ContainsKey(tokenUpp); if (flag) { try { this.token = double.Parse(this.InnerVariables[tokenUpp].ToString().Trim()).ToString(); this.tokType = ComputeEngineTokenType.TkNumber; } catch { this.token = this.InnerVariables[tokenUpp].ToString().Trim(); this.tokType = ComputeEngineTokenType.TkString; } } else { bool flag2 = this.ExternVariables.ContainsKey(tokenUpp); if (flag2) { try { this.token = double.Parse(this.ExternVariables[tokenUpp].ToString().Trim()).ToString(); this.tokType = ComputeEngineTokenType.TkNumber; } catch { this.token = this.ExternVariables[tokenUpp].ToString().Trim(); this.tokType = ComputeEngineTokenType.TkString; } } else { object variable = new object(); bool result = this.EvalUnkownVariable(tokenUpp, out variable); bool flag3 = result; if (!flag3) { throw new ComputeEngineParserException("未知变量:" + this.token + "!"); } try { this.token = double.Parse(variable.ToString().Trim()).ToString(); this.tokType = ComputeEngineTokenType.TkNumber; } catch { this.token = variable.ToString(); this.tokType = ComputeEngineTokenType.TkString; } } } }
private void GetToken() { this.tokType = ComputeEngineTokenType.TkNone; this.token = ""; bool flag = this.expIdx == this.exp.Length; if (!flag) { while (this.expIdx < this.exp.Length && char.IsWhiteSpace(this.exp[this.expIdx])) { this.expIdx++; } bool flag2 = this.expIdx == this.exp.Length; if (!flag2) { bool flag3 = this.IsDelim(this.exp[this.expIdx]); if (flag3) { this.token += this.exp[this.expIdx].ToString(); bool flag4 = this.exp[this.expIdx] == '<'; if (flag4) { this.expIdx++; bool b = false; bool flag5 = this.exp[this.expIdx] == '<' || this.exp[this.expIdx] == '=' || this.exp[this.expIdx] == '>'; if (flag5) { this.token += this.exp[this.expIdx].ToString(); b = true; } bool flag6 = !b; if (flag6) { this.expIdx--; } } else { bool flag7 = this.exp[this.expIdx] == '>'; if (flag7) { this.expIdx++; bool b = false; bool flag8 = this.exp[this.expIdx] == '=' || this.exp[this.expIdx] == '>'; if (flag8) { this.token += this.exp[this.expIdx].ToString(); b = true; } bool flag9 = !b; if (flag9) { this.expIdx--; } } } this.expIdx++; this.tokType = ComputeEngineTokenType.TkDelimiter; } else { bool flag10 = char.IsLetter(this.exp[this.expIdx]) || this.exp[this.expIdx] == '_'; if (flag10) { this.token += this.exp[this.expIdx].ToString(); this.expIdx++; bool flag11 = this.expIdx == this.exp.Length; if (!flag11) { while (char.IsLetter(this.exp[this.expIdx]) || char.IsDigit(this.exp[this.expIdx]) || this.exp[this.expIdx] == '.') { this.token += this.exp[this.expIdx].ToString(); this.expIdx++; bool flag12 = this.expIdx == this.exp.Length; if (flag12) { break; } } bool flag13 = this.expIdx != this.exp.Length; if (flag13) { bool flag14 = this.exp[this.expIdx] == '('; if (flag14) { this.tokType = ComputeEngineTokenType.TkFunction; } else { this.tokType = ComputeEngineTokenType.TkVariable; this.ReplaceVariable(); } } else { this.tokType = ComputeEngineTokenType.TkVariable; this.ReplaceVariable(); } } } else { bool flag15 = char.IsDigit(this.exp[this.expIdx]); if (flag15) { while (!this.IsDelim(this.exp[this.expIdx])) { this.token += this.exp[this.expIdx].ToString(); this.expIdx++; bool flag16 = this.expIdx >= this.exp.Length; if (flag16) { break; } } this.tokType = ComputeEngineTokenType.TkNumber; } else { bool flag17 = this.exp[this.expIdx] == '"' || this.exp[this.expIdx] == '\''; if (!flag17) { throw new ComputeEngineParserException("计算表达式定义非法符号" + this.exp[this.expIdx].ToString() + "!"); } this.expIdx++; while (this.exp[this.expIdx] != '"' && this.exp[this.expIdx] != '\'') { this.token += this.exp[this.expIdx].ToString(); this.expIdx++; bool flag18 = this.expIdx > this.exp.Length; if (flag18) { break; } } this.expIdx++; this.tokType = ComputeEngineTokenType.TkString; } } } } } }