}
/* format */
- char format[9] = "=> %..g\n";
format[5] = '0' + precision;
/* completion list*/
// test: echo -e '1 }\n1 )\n1 , 2\n ' | calc.exe | grep -c error | xargs test 3 =
// test: echo -e 'si\t\t (pi / 2)' | calc.exe | grep -q '=> 1'
+// Gauss sequence
+// test: echo -e '{sto (1, 0), sto (10, 0), while (inc (10) < 100, {sto (1, rcl (1) + rcl (10)), print (rcl (1))})}' | calc.exe | grep -q '=> 5050'
+
// Fibonacci sequence
-// test: echo -e '{sto (1, 1), sto (2, 1), sto (10, 1), while (inc (10) < 12 - 1, {sto (3, rcl (1) + rcl (2)), sto (1, rcl (2)), sto (2, rcl (3))})}' | calc.exe | grep '=> 144'
+// test: echo -e '{sto (1, 1), sto (2, 1), sto (10, 1), while (inc (10) < 12 - 1, {sto (3, rcl (1) + rcl (2)), sto (1, rcl (2)), print (sto (2, rcl (3)))})}' | calc.exe | grep '=> 144'
/* vim: set ts=4 sw=4 et: */
#define STORAGE_SIZE 10
double storage[STORAGE_SIZE] = {0};
+char format[9] = "=> %..g\n";
+
/* compare codes */
int codecmp (char *ref, char *str)
{ "|", Or, 2, 1, -2}
};
-#define NB_FUNCTIONS 23
+#define NB_FUNCTIONS 24
keyword_t functions[NB_FUNCTIONS] = {
{ "sqrt", Sqr, 1, 4, 5},
{ "pow", Pow, 2, 3, 5},
{ "help", Help, 0, 4, 9},
{ "!", Not, 1, 1, 6},
{ "cond", Cond, 3, 4, 5},
- { "while", While, 2, 5, 5}
+ { "while", While, 2, 5, 5},
+ { "print", Print, 1, 5, 5}
};
#define NB_CONSTANTS 3
case Cond: func = "Condition"; break;
case While: func = "While"; break;
case Prog: func = "Program"; break;
+ case Print: func = "Print"; break;
}
fprintf (stdout, "Function: %s\n", func);
fprintf (stdout, "storage functions:");
fprintf (stdout, " sto rcl inc dec\n");
fprintf (stdout, "conditional functions:");
- fprintf (stdout, " cond while\n");
+ fprintf (stdout, " cond while print {}\n");
fprintf (stdout, "miscellaneous functions:");
fprintf (stdout, " quit help\n");
fprintf (stdout, "supported constants:");
return 0;
}
break;
+ case Print:
+ op0 = (root->ops[0]) ? evaluate_element (root->ops[0], 0) : answer;
+ break;
}
switch (root->func) {
}
case While: return while_do (root->ops[0], root->ops[1]);
case Prog: return program_do (root->ops, root->nbops);
+ case Print: printf (format, op0); return op0;
}
return 0;