/* 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)
#ifndef __ELEMENT_H__
#define __ELEMENT_H__
-/* global variables */
-
/* function type */
typedef enum {
float prio;
} keyword_t;
+/* global variables */
+
+#define NB_OPERATORS 14
+extern keyword_t operators[];
+
+#define NB_FUNCTIONS 56
+extern keyword_t functions[];
+
+#define NB_CONSTANTS 3
+extern keyword_t constants[];
+
+#define NB_SYMBOLS 4
+extern char *symbols[];
+
/* calculus element type */
typedef struct _element_t {
return 0;
}
-/* functions */
-
-#define MAX_ARGS 100
-
-#define NB_OPERATORS 14
-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}
-};
-
-#define NB_FUNCTIONS 56
-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}
-};
-
-#define NB_CONSTANTS 3
-keyword_t constants[NB_CONSTANTS] = {
- { "ans", Ans, 0, 3, 5},
- { "e", E, 0, 1, 5},
- { "pi", Pi, 0, 2, 5}
-};
-
-#define NB_SYMBOLS 4
-char *symbols[NB_SYMBOLS] = {
- "(", ")", "{", "}"
-};
-
/* subparser function */
element_t *subparser (element_t **proot, char **pstr, func_t func, int nbops, int prio)
return 0;
}
-char **generate_completion_list ()
-{
- int i, j, l = 0;
- char **list = (char **) callocordie (NB_OPERATORS + NB_FUNCTIONS + NB_CONSTANTS + NB_SYMBOLS + 1, sizeof (char *));
-
- for (i = 0; i < NB_OPERATORS; i++) {
- list[l] = strdup ((operators + i)->keyword);
- for (j = 0; j < (int)strlen (list[l]); j++) {
- if (list[i][j] == '\t') {
- list[i][j] = '\0';
- }
- }
- if (list[l] != NULL) {
- l++;
- }
- }
-
- for (i = 0; i < NB_FUNCTIONS; i++) {
- list[l] = strdup ((functions + i)->keyword);
- if (list[l] != NULL) {
- l++;
- }
- }
-
- for (i = 0; i < NB_CONSTANTS; i++) {
- list[l] = strdup ((constants + i)->keyword);
- if (list[l] != NULL) {
- l++;
- }
- }
-
- for (i = 0; i < NB_SYMBOLS; i++) {
- list[l] = strdup (symbols[i]);
- if (list[l] != NULL) {
- l++;
- }
- }
-
- return (list);
-}
-
-void free_completion_list (char **list)
-{
- int i;
-
- if (list) {
- for (i = 0; i < NB_OPERATORS + NB_FUNCTIONS + NB_CONSTANTS + NB_SYMBOLS + 1; i++) {
- if (list[i] != NULL) {
- free (list[i]);
- }
- }
- free (list);
- }
-}
-
/* vim: set ts=4 sw=4 et: */
extern double answer;
-/* completion functions */
-
-char **generate_completion_list ();
-
-void free_completion_list (char **list);
-
/* parser function */
void delelement (element_t *root);
#include <readline/readline.h>
#include <readline/history.h>
+#include "alloc.h"
#include "debug.h"
-#include "parser.h"
+#include "element.h"
#include "readline.h"
free (buffer);
}
}
+
+/* generate completion list */
+
+char **generate_completion_list ()
+{
+ int i, j, l = 0;
+ char **list = (char **) callocordie (NB_OPERATORS + NB_FUNCTIONS + NB_CONSTANTS + NB_SYMBOLS + 1, sizeof (char *));
+
+ for (i = 0; i < NB_OPERATORS; i++) {
+ list[l] = strdup ((operators + i)->keyword);
+ for (j = 0; j < (int)strlen (list[l]); j++) {
+ if (list[i][j] == '\t') {
+ list[i][j] = '\0';
+ }
+ }
+ if (list[l] != NULL) {
+ l++;
+ }
+ }
+
+ for (i = 0; i < NB_FUNCTIONS; i++) {
+ list[l] = strdup ((functions + i)->keyword);
+ if (list[l] != NULL) {
+ l++;
+ }
+ }
+
+ for (i = 0; i < NB_CONSTANTS; i++) {
+ list[l] = strdup ((constants + i)->keyword);
+ if (list[l] != NULL) {
+ l++;
+ }
+ }
+
+ for (i = 0; i < NB_SYMBOLS; i++) {
+ list[l] = strdup (symbols[i]);
+ if (list[l] != NULL) {
+ l++;
+ }
+ }
+
+ return (list);
+}
+
+/* free completion list */
+
+void free_completion_list (char **list)
+{
+ int i;
+
+ if (list) {
+ for (i = 0; i < NB_OPERATORS + NB_FUNCTIONS + NB_CONSTANTS + NB_SYMBOLS + 1; i++) {
+ if (list[i] != NULL) {
+ free (list[i]);
+ }
+ }
+ free (list);
+ }
+}
+
+/* vim: set ts=4 sw=4 et: */
void manage_history (char *buffer);
void clean_read_line (char *buffer);
+char **generate_completion_list ();
+void free_completion_list (char **list);
+
#endif /* __READLINE_H__ */
+
+/* vim: set ts=4 sw=4 et: */