コード例 #1
0
 private Expression.Expression ConvertFunction(FunctionNode node)
 {
     if (FunctionTable.IsValidFunction(node.FunctionName))
     {
         //check number of arguments
         FunctionEntry entry = FunctionTable.GetFunctionEntry(node.FunctionName);
         if (entry.ArgNumber != node.Arguments.Count)
         {
             compilerErrors.Add(new ErrorMessage($"{entry.ArgNumber.ToString()} аргументов ожидалось в функции \"{node.FunctionName}", node.Line, node.Position));
             return(null);
         }
         List <Expression.Expression> arguments = new List <Expression.Expression>();
         foreach (var argument in node.Arguments)
         {
             arguments.Add(ConvertToExpression(argument));
         }
         return(new Function(entry, arguments));
     }
     else
     {
         compilerErrors.Add(new ErrorMessage($"Неизвестная функция \"{node.FunctionName}\"", node.Line, node.Position));
         return(null);
     }
 }