#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;