move all code relative to readline into separate file (2)
[calc.git] / element.c
index 19c30df8d2a0b25ccd20f564ee3ebd1dfed06751..e285504a1bf69fded6f64cccb8ed2b110b7a8349 100644 (file)
--- a/element.c
+++ b/element.c
@@ -6,6 +6,94 @@
 
 /* global variables */
 
+#define MAX_ARGS 100
+
+keyword_t operators[NB_OPERATORS] = {
+    { "+\t", Add, 2, 1, 1},
+    { "-\t", Sub, 2, 1, 1},
+    { "*",   Mul, 2, 1, 2},
+    { "/",   Div, 2, 1, 2},
+    { "%",   Mod, 2, 1, 3},
+    { "^",   Pow, 2, 1, 4},
+    { "==",  Equal, 2, 2, -1},
+    { "!=",  Diff, 2, 2, -1},
+    { ">=",  Ge, 2, 2, -1},
+    { "<=",  Le, 2, 2, -1},
+    { ">",   Gt, 2, 1, -1},
+    { "<",   Lt, 2, 1, -1},
+    { "&",   And, 2, 1, -2},
+    { "|",   Or, 2, 1, -2}
+};
+
+keyword_t functions[NB_FUNCTIONS] = {
+    { "sqrt", Sqr, 1, 4, 5},
+    { "pow",  Pow, 2, 3, 5},
+    { "cos",  Cos, 1, 3, 5},
+    { "sin",  Sin, 1, 3, 5},
+    { "tan",  Tan, 1, 3, 5},
+    { "acos", Acos, 1, 4, 5},
+    { "asin", Asin, 1, 4, 5},
+    { "atan", Atan, 1, 4, 5},
+    { "ln",   Ln, 1, 2, 5},
+    { "log",  Log, 1, 3, 5},
+    { "exp",  Exp, 1, 3, 5},
+    { "erfc", Erfc, 1, 4, 5},
+    { "erf",  Erf, 1, 3, 5},
+    { "abs",  Abs, 1, 3, 5},
+    { "floor", Floor, 1, 5, 5},
+    { "ceil", Ceil, 1, 4, 5},
+    { "sto",  Store, 2, 3, 5},
+    { "rcl",  Recall, 1, 3, 5},
+    { "inc",  Inc, 1, 3, 5},
+    { "dec",  Dec, 1, 3, 5},
+    { "disp", Disp, 0, 4, 9},
+    { "mem",  Memory, 1, 3, 5},
+    { "clr",  Clear, 0, 3, 9},
+    { "quit", Quit, 0, 4, 9},
+    { "help", Help, 0, 4, 9},
+    { "hist", History, 0, 4, 9},
+    { "!",    Not, 1, 1, 6},
+    { "cond", Cond, 3, 4, 5},
+    { "while", While, 2, 5, 5},
+    { "print", Print, 1, 5, 5},
+    { "prog", Prog, 2, 4, 9},
+    { "arg",  Arg, 1, 3, 5},
+    { "call", Call, MAX_ARGS, 4, 5},
+    { "ls",   List, 0, 2, 9},
+    { "edit", Edit, 1, 4, 9},
+    { "del",  Del, 1, 3, 9},
+    { "get",  Get, 1, 3, 5},
+    { "len",  Length, 0, 3, 5},
+    { "pop",  Pop, 0, 3, 5},
+    { "push", Push, 1, 4, 5},
+    { "put",  Put, 2, 3, 5},
+    { "set",  Set, MAX_ARGS, 3, 5},
+    { "show", Show, 0, 4, 5},
+    { "max",  Max, 2, 3, 5},
+    { "mean", Mean, 2, 4, 5},
+    { "med",  Median, 0, 3, 5},
+    { "min",  Min, 2, 3, 5},
+    { "ord",  Order, 0, 3, 5},
+    { "prod", Prod, 0, 4, 5},
+    { "sum",  Sum, 0, 3, 5},
+    { "var",  Variance, 2, 3, 5},
+    { "format", Precision, 1, 6, 9},
+    { "base", Base, 2, 4, 9},
+    { "deg", Deg, 0, 3, 9},
+    { "grad", Grad, 0, 4, 9},
+    { "rad", Rad, 0, 3, 9}
+};
+
+keyword_t constants[NB_CONSTANTS] = {
+    { "ans", Ans, 0, 3, 5},
+    { "e",   E, 0, 1, 5},
+    { "pi",  Pi, 0, 2, 5}
+};
+
+char *symbols[NB_SYMBOLS] = {
+    "(", ")", "{", "}"
+};
+
 /* allocate new element */
 
 element_t *newelement (func_t function, int nbops, int prio)