(l = 1; 
x1 = 
          l*Sin[φ1[t]]; 
x2 = 
          x1 + l*Sin[φ2[t]]; 
x3 = 
          x2 + l*Sin[φ3[t]]; 
y1 = 
          l*Cos[φ1[t]]; 
y2 = 
          y1 + l*Cos[φ2[t]]; 
y3 = 
          y2 + l*Cos[φ3[t]];)

(x1p = D[x1, t]; x2p = D[x2, t]; 
        x3p = D[x3, t]; 
y1p = D[y1, t]; y2p = D[y2, t]; 
        y3p = D[y3, t];)

L = (1/2)*(x1p^2 + x2p^2 + x3p^2 + y1p^2 + y2p^2 + 
                    y3p^2) + grav*(y1 + y2 + y3) // 
            Simplify;

(Gleichung1=D[D[L,(φ1)'[t]],t]==D[L, φ1[t]]//Simplify;
Gleichung2=D[D[L,(φ2)'[t]],t]==D[L, φ2[t]]//Simplify;
Gleichung3=D[D[L,(φ3)'[t]],t]==D[L, φ3[t]]//Simplify;)

Lsgn=Solve[{Gleichung1, Gleichung2, Gleichung3},{(φ1)''[t],(φ2)''[t],(φ3)''[t]}]//Flatten;

((φ1)'[t]=omega1; (φ2)'[t]=omega2; (φ3)'[t]=omega3;φ1[t] = phi1; φ2[t] = phi2; φ3[t] = phi3;)

(force1=Lsgn[[1, 2]] // Expand // Simplify // 
              InputForm;
\(StringReplace[
            ToString[
              force1], {"Sin[" -> "Math.sin(", "Cos[" -> "Math.cos(", "]" -> ")"
, "omega1^2" -> "omega1*omega1", "omega2^2" -> "omega2*omega2", "omega3^2" -> "omega3*omega3"}]\))

(force2=Lsgn[[2, 2]] // Expand // Simplify // 
              InputForm;
\(StringReplace[
            ToString[
              force2], {"Sin[" -> "Math.sin(", "Cos[" -> "Math.cos(", "]" -> ")"
, "omega1^2" -> "omega1*omega1", "omega2^2" -> "omega2*omega2", "omega3^2" -> "omega3*omega3"}]\))

(force3=Lsgn[[3, 2]] // Expand // Simplify // 
              InputForm;
\(StringReplace[
            ToString[
              force3], {"Sin[" -> "Math.sin(", "Cos[" -> "Math.cos(", "]" -> ")"
, "omega1^2" -> "omega1*omega1", "omega2^2" -> "omega2*omega2", "omega3^2" -> "omega3*omega3"}]\))

(\(Energy = \(\((1/2)\)*\((x1p^2 + x2p^2 + x3p^2 + y1p^2 + 
                      y2p^2 + y3p^2)\) - grav*\((y1 + y2 + y3)\) // 
              Simplify\) // InputForm; 
StringReplace[
          ToString[
            Energy], {"Sin[" -> "Math.sin(", "Cos[" -> "Math.cos(", "]" -> ")"
, "omega1^2" -> "omega1*omega1", "omega2^2" -> "omega2*omega2", "omega3^2" -> "omega3*omega3"}]\))