public Variable Execute(Space space) { if (!Sentence.IsSuccess(_valueExpression.Execute(space))) { ErrorLogger.LogRuntimeError(ErrorRuntimeCode.VariableArrayItemAnalysis, "The expression execute failed!"); return null; } var retValue = _valueExpression.value; Variable retVariable = null; var expressionVecSize = _indexExpressionVec.Count; for (var i = 0; i < expressionVecSize; ++i) { if (!ValueTool.IsArray(retValue)) { ErrorLogger.LogRuntimeError(ErrorRuntimeCode.VariableArrayItemAnalysis, "The result of expression isn't a array!"); return null; } var arr = (retValue as ValueArray).value; var expression = _indexExpressionVec[i]; if (!Sentence.IsSuccess(expression.Execute(space))) { ErrorLogger.LogRuntimeError(ErrorRuntimeCode.VariableArrayItemAnalysis, "The expression execute failed!"); return null; } var indexValue = expression.value; if (!ValueTool.IsInteger(indexValue)) { ErrorLogger.LogRuntimeError(ErrorRuntimeCode.VariableArrayItemAnalysis, "The index isn't a integer value!"); return null; } var index = (int) ((indexValue as ValueNumber).value); if (index >= arr.Count) { ErrorLogger.LogRuntimeError(ErrorRuntimeCode.VariableArrayItemAnalysis, "The index out of range!"); return null; } retVariable = arr[index]; if (!retVariable) { ErrorLogger.LogRuntimeError(ErrorRuntimeCode.VariableArrayItemAnalysis, "The array value is invalid!"); return null; } retValue = retVariable.value; } return retVariable; }
private static Sentence _ParseEnumDefine(string src, int size, int pos, out int nextPos) { nextPos = pos; if (!Grammar.MatchEnum(src, size, pos, out pos)) { return null; } if (!Jump(src, size, pos, out pos)) { return null; } string name; if (!Grammar.MatchName(src, size, pos, out pos, out name)) { return null; } Jump(src, size, pos, out pos); if (!Grammar.MatchObjectBegin(src, size, pos, out pos)) { return null; } var checkNameSet = new HashSet<string>(); var checkValueSet = new HashSet<double>(); var valueList = new LinkedList<KeyValuePair<string, ValueNumber>>(); double indexValue = 0; while (true) { if (pos >= size) { return null; } Jump(src, size, pos, out pos); if (Grammar.MatchObjectEnd(src, size, pos, out pos)) { break; } string valueName = ""; if (!Grammar.MatchName(src, size, pos, out pos, out valueName)) { return null; } Jump(src, size, pos, out pos); if (Grammar.MatchAssign(src, size, pos, out pos)) { Jump(src, size, pos, out pos); if (!Grammar.MatchNumber(src, size, pos, out pos, out indexValue)) { return null; } Jump(src, size, pos, out pos); } var valueNumber = new ValueNumber(indexValue); if (!ValueTool.IsInteger(valueNumber)) { return null; } if (checkNameSet.Contains(valueName)) { return null; } if (checkValueSet.Contains(indexValue)) { return null; } checkNameSet.Add(valueName); checkValueSet.Add(indexValue); valueList.AddLast(new KeyValuePair<string, ValueNumber>(valueName, valueNumber)); Jump(src, size, pos, out pos); if (!Grammar.MatchSplitSymbol(src, size, pos, out pos)) { if (Grammar.MatchObjectEnd(src, size, pos, out pos)) { break; } return null; } indexValue += 1; } nextPos = pos; return new SentenceEnumDefine(name, valueList); }