/// <summary> /// Evalaute this node and return result. /// </summary> /// <param name="thisObject">Reference to object that is exposed as 'this'.</param> /// <returns>Result value and type of that result.</returns> public override EvalResult Evaluate(object thisObject) { EvalResult target = this[0].Evaluate(thisObject); EvalNodeArgList args = (EvalNodeArgList)this[1]; if (target.Value == null) { throw new ApplicationException("Cannot access '" + Identifier + "' on a value of 'null'."); } // Evalute all the arguments EvalResult[] results = new EvalResult[args.Count]; for (int i = 0; i < results.Length; i++) { results[i] = args[i].Evaluate(thisObject); } if (target.Value is Type) { return(EvaluateTypeMethod(target, results)); } else { return(EvaluateObjectMethod(target, results)); } }
/// <summary> /// Evalaute this node and return result. /// </summary> /// <param name="thisObject">Reference to object that is exposed as 'this'.</param> /// <returns>Result value and type of that result.</returns> public override EvalResult Evaluate(object thisObject) { EvalResult target = this[0].Evaluate(thisObject); EvalNodeArgList args = (EvalNodeArgList)this[1]; // We can only handle a target that is an object if (target.Type != TypeCode.Object) { throw new ApplicationException("Array index cannot index a value of type '" + target.Type.ToString() + "'."); } else if (target.Value == null) { throw new ApplicationException("Array index cannot index a value of 'null'."); } else if (target.Value is Type) { throw new ApplicationException("Array index cannot index a 'type' object."); } // Evalute all the arguments EvalResult[] results = new EvalResult[args.Count]; for (int i = 0; i < results.Length; i++) { results[i] = args[i].Evaluate(thisObject); } // Is this an actual array of a type? if (target.Value.GetType().IsArray) { return(EvaluateObjectArray(target, results, thisObject)); } else { return(EvaluateObjectInstance(target, results, thisObject)); } }
/// <summary> /// Process the 'arglist2' rule. /// </summary> /// <remarks> /// /// arglist2 ::= ',' expression arglist2 | /// {empty} /// ///</remarks> /// <returns>Parsed node.</returns> protected virtual EvalNodeArgList ParseArgList2() { if (Tokeniser.Next(TokenType.Comma)) { EvalNodeArgList args = new EvalNodeArgList(ParseExpression(), Language); EvalNodeArgList arg2 = ParseArgList2(); if (arg2 != null) args.Append(arg2.RemoveAll()); return args; } return null; }
/// <summary> /// Process the 'arglist1' rule. /// </summary> /// <remarks> /// /// arglist1 ::= expression arglist2 | /// /// </remarks> /// <returns>Parsed node.</returns> protected virtual EvalNode ParseArgList1() { EvalNode args = new EvalNodeArgList(ParseExpression(), Language); EvalNodeArgList arg2 = ParseArgList2(); if (arg2 != null) args.Append(arg2.RemoveAll()); return args; }
/// <summary> /// Process the 'arglist' rule. /// </summary> /// <remarks> /// /// arglist ::= expression arglist2 | /// {empty} /// /// </remarks> /// <returns>Parsed node.</returns> protected virtual EvalNode ParseArgList() { if (Tokeniser.Peek.Type != TokenType.CloseRoundBracket) { EvalNode args = new EvalNodeArgList(ParseExpression(), Language); EvalNodeArgList arg2 = ParseArgList2(); if (arg2 != null) args.Append(arg2.RemoveAll()); return args; } return null; }