public bool AssignValue(AleTerm assignTo, ref AleTermResult value, TermEvaluate userEvaluate, TermAssign userAssign) { switch (assignTo.TypeOfTerm) { case AleTermType.Variable: return(UserAssign(assignTo.Value.ToString(), assignTo.HashCode, null, null, ref value, userAssign)); case AleTermType.Operation: if (assignTo.Operation != null) { AleTermResult a = new AleTermResult(); AleTermResult b = new AleTermResult(); if (assignTo.Operation.IsClassOperator) { if (!assignTo[0].Evaluate(out a, userEvaluate, userAssign) && value.SetError(a.ErrorCode, a.ErrorPos)) { return(false); } return(assignTo[1].TypeOfTerm == AleTermType.Variable && UserAssign(assignTo[1].Value.ToString(), assignTo[1].HashCode, a.Value, null, ref value, userAssign)); } else if (assignTo.Operation.IsIndexOperator) { List <object> list; if (!assignTo[0].Evaluate(out a, userEvaluate, userAssign) && value.SetError(a.ErrorCode, a.ErrorPos)) { return(false); } int n = assignTo[1].Count; list = new List <object>(); for (int i = 0; i < n; i++) { if (assignTo[1][i] != null) { if (!assignTo[1][i].Evaluate(out b, userEvaluate, userAssign) && value.SetError(b.ErrorCode, b.ErrorPos)) { return(false); } } else { b.Value = null; } list.Add(b.Value); } return(UserAssign(null, 0, a.Value, list, ref value, userAssign)); } } break; } value.SetError(AleTermResult.ERROR_GENERAL, assignTo.Token.StartInOrigin); return(false); }
public AleTerm(AleTermType type, AleExpressionParser parser) { _Type = type; _Hash = 0; _Value = null; _Parent = null; _Token = null; _Elements = null; _Parser = parser; _Operation = null; }
public AleTerm() { _Type = AleTermType.Unknown; _Hash = 0; _Value = null; _Parent = null; _Token = null; _Elements = null; _Parser = null; _Operation = null; }
private void GetVariablesList(List <Tuple <int, string> > res) { if (TypeOfTerm == AleTermType.Variable) { string s = _Value.ToString(); int n = res.Count; for (int i = 0; i < n; i++) { if (res[i].Item1 == _Hash && res[i].Item2 == s) { return; } } res.Add(new Tuple <int, string>(_Hash, s)); } else if (TypeOfTerm == AleTermType.Operation) { if (_Operation != null && _Operation.IsClassOperator) { AleTerm T = _Elements[0]; while (T.Operation != null && T.Operation.IsClassOperator) { T = T._Elements[0]; } T.GetVariablesList(res); T = _Elements[1]; if (T.TypeOfTerm == AleTermType.Operation) { T.GetVariablesList(res); } } else if (_Elements != null) { int n = _Elements.Count; for (int i = 0; i < n; i++) { if (_Elements[i] != null) { _Elements[i].GetVariablesList(res); } } } } }
// evaluation private void OnEvaluate(AleTerm term, AleTermEvaluateArgs e) { bool ignoreCase = chkIgnoreCase.Checked; object res; if (e.Instance == null) { if (Variables.TryGetValue(e.Name, out res)) e.Result = res; else { res = (int)0; Variables.Add(e.Name, res); e.Result = res; } return; } }
// assignment private void OnAssign(AleTerm term, AleTermAssignArgs e) { bool ignoreCase = chkIgnoreCase.Checked; if (e.Instance == null) { Variables[e.Name] = e.Value; return; } e.SetError(AleTermResult.ERROR_UNKNOWNELEMENT, term.Token.StartInOrigin); }
public bool AssignValue(AleTerm assignTo, ref AleTermResult value, TermEvaluate userEvaluate, TermAssign userAssign) { switch (assignTo.TypeOfTerm) { case AleTermType.Variable: return UserAssign(assignTo.Value.ToString(), assignTo.HashCode, null, null, ref value, userAssign); case AleTermType.Operation: if (assignTo.Operation != null) { AleTermResult a = new AleTermResult(); AleTermResult b = new AleTermResult(); if (assignTo.Operation.IsClassOperator) { if (!assignTo[0].Evaluate(out a, userEvaluate, userAssign) && value.SetError(a.ErrorCode, a.ErrorPos)) return false; return assignTo[1].TypeOfTerm == AleTermType.Variable && UserAssign(assignTo[1].Value.ToString(), assignTo[1].HashCode, a.Value, null, ref value, userAssign); } else if (assignTo.Operation.IsIndexOperator) { List<object> list; if (!assignTo[0].Evaluate(out a, userEvaluate, userAssign) && value.SetError(a.ErrorCode, a.ErrorPos)) return false; int n = assignTo[1].Count; list = new List<object>(); for (int i = 0; i < n; i++) { if (assignTo[1][i] != null) { if (!assignTo[1][i].Evaluate(out b, userEvaluate, userAssign) && value.SetError(b.ErrorCode, b.ErrorPos)) return false; } else b.Value = null; list.Add(b.Value); } return UserAssign(null, 0, a.Value, list, ref value, userAssign); } } break; } value.SetError(AleTermResult.ERROR_GENERAL, assignTo.Token.StartInOrigin); return false; }