public static void CheckExpressionWithGlobalVariable(Expression e1, List<string> parameters, CommonTree ParentTree, IToken defaultToken) { //if e has only one var, this means e is a input variable List<string> evars = e1.GetVars(); if (evars.Count >= 1) { foreach (string var in evars) { IToken token = Common.Utility.ParsingUltility.GetVariableTokenInTree(ParentTree, var); if (token == null) { throw new ParsingException("Parsing error in expression " + e1.ToString(), defaultToken); } //if not contained in the parameters, then the variable is in the global variables if (!parameters.Contains(var)) { throw new ParsingException("Only process parameter and constants can be used in expression " + e1 + "! Global variable is not supported here for performance reason!", token); } } } }
//public override String GetID() //{ // StringBuilder sb = new StringBuilder(Variable+ "." + MethodName + "("); // for (int i = 0; i < Arguments.Length; i++) // { // if (i == Arguments.Length - 1) // { // sb.Append(Arguments[i].GetID()); // } // else // { // sb.Append(Arguments[i].GetID() + ","); // } // } // sb.Append(")"); // return sb.ToString(); //} public override List <string> GetVars() { return(Variable.GetVars()); }
public static IntConstant EvaluateIntExpression(Expression exp, IToken token, Dictionary<string, Expression> constantDB) { try { if (constantDB.Count > 0) { exp = exp.ClearConstant(constantDB); } if (exp.HasVar) { List<string> vars = exp.GetVars(); throw new ParsingException(string.Format(Resources.Variables___0___can_not_be_used_in_this_expression_, Classes.Ultility.Ultility.PPStringList(vars)) + exp, token); } ExpressionValue rhv = EvaluatorDenotational.Evaluate(exp, null); if (rhv is IntConstant) { return rhv as IntConstant; } else { throw new ParsingException(Resources.The_expression_should_return_an_integer_value_, token); } } catch (Exception ex) { throw new ParsingException(ex.Message, token); } }
//public static void CheckParameterVarUsedInMathExpression(Expression e1, Dictionary<string, string> ParameterVariables, IToken token) //{ // if (e1 is Variable) // { // string name = ((Variable) e1).VarName; // if (ParameterVariables.ContainsKey(name)) // { // throw new ParsingException("Can not use parameter variable " + name + " in math expression!", token); // } // } //} public static void CheckTimedExpressionWithGlobalVariable(Expression e1, IToken token, Dictionary<string, Expression> ConstantDatabase, List<IToken> GlobalVarNames) { if (ConstantDatabase.Count > 0) { e1 = e1.ClearConstant(ConstantDatabase); } List<string> evars = e1.GetVars(); if (evars.Count >= 1) { foreach (string evar in evars) { foreach (IToken gvar in GlobalVarNames) { if (gvar.Text == evar) { throw new ParsingException("Global variable (" + evar + ") cannot be used in timed process!", token); } } } } }