//---------------------------------------- // Получение значения числа или переменной //---------------------------------------- private void atom() { if (currentToken.Type == StiTokenType.Variable) { asmList.Add(new StiAsmCommand(StiAsmCommandType.PushVariable, currentToken.Value)); get_token(); return; } else if (currentToken.Type == StiTokenType.SystemVariable) { asmList.Add(new StiAsmCommand(StiAsmCommandType.PushSystemVariable, SystemVariablesList[currentToken.Value])); get_token(); return; } else if (currentToken.Type == StiTokenType.Function) { StiToken function = currentToken; StiFunctionType functionType = (StiFunctionType)FunctionsList[function.Value]; asmList.Add(new StiAsmCommand(StiAsmCommandType.PushFunction, functionType, get_args_count(functionType))); get_token(); return; } else if (currentToken.Type == StiTokenType.Method) { StiToken method = currentToken; StiMethodType methodType = (StiMethodType)MethodsList[method.Value]; asmList.Add(new StiAsmCommand(StiAsmCommandType.PushMethod, methodType, get_args_count(methodType) + 1)); get_token(); return; } else if (currentToken.Type == StiTokenType.Property) { StiToken function = currentToken; asmList.Add(new StiAsmCommand(StiAsmCommandType.PushProperty, PropertiesList[function.Value])); get_token(); return; } else if (currentToken.Type == StiTokenType.DataSourceField) { asmList.Add(new StiAsmCommand(StiAsmCommandType.PushDataSourceField, currentToken.Value)); get_token(); return; } else if (currentToken.Type == StiTokenType.BusinessObjectField) { asmList.Add(new StiAsmCommand(StiAsmCommandType.PushBusinessObjectField, currentToken.Value)); get_token(); return; } else if (currentToken.Type == StiTokenType.Component) { asmList.Add(new StiAsmCommand(StiAsmCommandType.PushComponent, ComponentsList[currentToken.Value])); get_token(); return; } else if (currentToken.Type == StiTokenType.Number) { asmList.Add(new StiAsmCommand(StiAsmCommandType.PushValue, currentToken.ValueObject)); get_token(); return; } else if (currentToken.Type == StiTokenType.String) { asmList.Add(new StiAsmCommand(StiAsmCommandType.PushValue, currentToken.ValueObject)); get_token(); return; } else { if (currentToken.Type == StiTokenType.Empty) { ThrowError(ParserErrorCode.UnexpectedEndOfExpression); //неожиданный конец выражения } ThrowError(ParserErrorCode.SyntaxError, currentToken); //cинтаксическая ошибка } }
//---------------------------------------- // Получение значения числа или переменной //---------------------------------------- private void atom() { switch (currentToken.Type) { case StiTokenType.Variable: asmList.Add(new StiAsmCommand(StiAsmCommandType.PushVariable, currentToken.Value)); get_token(); return; case StiTokenType.SystemVariable: asmList.Add(new StiAsmCommand(StiAsmCommandType.PushSystemVariable, SystemVariablesList[currentToken.Value])); get_token(); return; case StiTokenType.Function: { StiToken function = currentToken; ProryvFunctionType functionType; var objFunc = FunctionsList[function.Value]; if (objFunc != null) { functionType = (ProryvFunctionType)objFunc; } else { functionType = (ProryvFunctionType)UserFunctionsList[function.Value]; } asmList.Add(new StiAsmCommand(StiAsmCommandType.PushFunction, functionType, get_args_count(functionType))); get_token(); return; } case StiTokenType.ProryvFunction: var args = get_args(); asmList.Add(new StiAsmCommand(StiAsmCommandType.PushFunction, ProryvFunctionType.proryvFunction, args.Count)); get_token(); return; case StiTokenType.ProryvSpreadsheetProperties: { StiToken function = currentToken; asmList.Add(new StiAsmCommand(StiAsmCommandType.ProryvSpreadsheetProperty, _proryvSpreadsheetProperties[function.Value.ToLowerInvariant()])); get_token(); return; } case StiTokenType.ProryvFreeHierarchyBalanceSignature: { StiToken function = currentToken; asmList.Add(new StiAsmCommand(StiAsmCommandType.ProryvFreeHierarchyBalanceSignature, _proryvFreeHierarchyBalanceSignature[function.Value.ToLowerInvariant()])); get_token(); return; } case StiTokenType.Method: StiToken method = currentToken; StiMethodType methodType = (StiMethodType)MethodsList[method.Value]; asmList.Add(new StiAsmCommand(StiAsmCommandType.PushMethod, methodType, get_args_count(methodType) + 1)); get_token(); return; case StiTokenType.Property: { StiToken function = currentToken; asmList.Add(new StiAsmCommand(StiAsmCommandType.PushProperty, PropertiesList[function.Value])); get_token(); return; } case StiTokenType.DataSourceField: asmList.Add(new StiAsmCommand(StiAsmCommandType.PushDataSourceField, currentToken.Value)); get_token(); return; case StiTokenType.BusinessObjectField: asmList.Add(new StiAsmCommand(StiAsmCommandType.PushBusinessObjectField, currentToken.Value)); get_token(); return; case StiTokenType.Number: asmList.Add(new StiAsmCommand(StiAsmCommandType.PushValue, currentToken.ValueObject)); get_token(); return; case StiTokenType.String: asmList.Add(new StiAsmCommand(StiAsmCommandType.PushValue, currentToken.ValueObject)); get_token(); return; default: if (currentToken.Type == StiTokenType.Empty) { ThrowError(ParserErrorCode.UnexpectedEndOfExpression); //неожиданный конец выражения } ThrowError(ParserErrorCode.SyntaxError, currentToken); //cинтаксическая ошибка break; } }
private Type GetMethodResultType(StiMethodType type, Type[] args) { Type baseType = args[0]; int count = args.Length - 1; string methodName = type.ToString(); MethodInfo[] methods = baseType.GetMethods(); bool flag0 = false; bool flag1 = false; foreach (var mi in methods) { if (mi.Name != methodName) { continue; } flag0 = true; ParameterInfo[] pi = mi.GetParameters(); if (pi.Length != count) { continue; } flag1 = true; bool flag2 = true; for (int index = 0; index < count; index++) { if (IsImplicitlyCastableTo(args[index + 1], pi[index].ParameterType)) { continue; } flag2 = false; break; } if (flag2) { return(mi.ReturnType); } } if (!flag0) { ThrowError(ParserErrorCode.FieldMethodOrPropertyNotFound, Enum.GetName(typeof(StiMethodType), type)); } if (!flag1) { ThrowError(ParserErrorCode.NoOverloadForMethodTakesNArguments, Enum.GetName(typeof(StiMethodType), type), count.ToString()); } StringBuilder sb = new StringBuilder(); for (int index = 0; index < count; index++) { sb.Append(args[index + 1].Namespace == "System" ? args[index + 1].Name : args[index + 1].ToString()); if (index < count - 1) { sb.Append(","); } } ThrowError(ParserErrorCode.NoMatchingOverloadedMethod, Enum.GetName(typeof(StiMethodType), type), sb.ToString()); return(typeof(object)); }