clean help message
[calc.git] / parser.c
index 05b89c936b8a6d96b868f440aed06adc5323a4fa..53d6e6c78efdea14be71bc4ddc216ddbcc005687 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -70,7 +70,6 @@ void delelement (element_t *root)
 /* functions */
 
 #define NB_OPERATORS 14
-
 keyword_t operators[NB_OPERATORS] = {
     { "+\t", Add, 2, 1, 1},
     { "-\t", Sub, 2, 1, 1},
@@ -102,7 +101,7 @@ keyword_t functions[NB_FUNCTIONS] = {
     { "disp", Disp, 0, 4, 9},
     { "quit", Quit, 0, 4, 9},
     { "help", Help, 0, 4, 9},
-    { "!",    Not, 1, 1, 5}
+    { "!",    Not, 1, 1, 6}
 };
 
 #define NB_CONSTANTS 3
@@ -326,13 +325,28 @@ element_t *parser (char *str, char **next, int prio)
             double value = strtod (str, &pt);
             VERBOSE (INFO, fprintf (stdout, "Value: %f\n", value));
             if (str != pt) {
-                if (root == NULL) {
+                if ((root == NULL) || (root->prio == 6)) {
                     new = newelement (Val, 1, 5);
                     if (new == NULL) {
                         return ERROR_OP;
                     }
                     new->value = value;
-                    root = new;
+                    if (root == NULL) {
+                        root = new;
+                    } else {
+                        for (i = 0; i < root->nbops; i++) {
+                            if (root->ops[i] == NULL) {
+                                root->ops[i] = new;
+                                found = 1;
+                                break;
+                            }
+                        }
+                        if (!found) {
+                            delelement (new);
+                            delelement (root);
+                            return ERROR_OP;
+                        }
+                    }
                     str = pt;
                 } else if ((*str == '+') || (*str == '-')) {
                     if ((prio) && (prio > 1)) {
@@ -481,6 +495,8 @@ void help (void)
     fprintf (stdout, " + - * / %% ^\n\n");
     fprintf (stdout, "camparison operators:\n");
     fprintf (stdout, " == != >= <= > <\n\n");
+    fprintf (stdout, "logical operators:\n");
+    fprintf (stdout, " & | !\n\n");
     fprintf (stdout, "supported functions:\n");
     fprintf (stdout, " pow sqrt cos sin atan log exp\n\n");
     fprintf (stdout, "storage functions:\n");