very partial program functions
authorLaurent Mazet <mazet@softndesign.org>
Sun, 29 Jan 2023 22:21:30 +0000 (23:21 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 29 Jan 2023 22:21:30 +0000 (23:21 +0100)
parser.c
parser.h

index 38b7c2692fad24c3a4c9422caa92d3214ad70c3c..395e2aea1e90642757ab4cf6fb2d891058d479a1 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -21,6 +21,8 @@ double *storage = NULL;
 char *format = NULL;
 char *minform = NULL;
 
+workspace_t *programs = NULL;
+
 /* compare codes */
 
 int codecmp (char *ref, char *str)
@@ -122,7 +124,7 @@ keyword_t operators[NB_OPERATORS] = {
     { "|",   Or, 2, 1, -2}
 };
 
-#define NB_FUNCTIONS 26
+#define NB_FUNCTIONS 31
 keyword_t functions[NB_FUNCTIONS] = {
     { "sqrt", Sqr, 1, 4, 5},
     { "pow",  Pow, 2, 3, 5},
@@ -149,7 +151,12 @@ keyword_t functions[NB_FUNCTIONS] = {
     { "!",    Not, 1, 1, 6},
     { "cond", Cond, 3, 4, 5},
     { "while", While, 2, 5, 5},
-    { "print", Print, 1, 5, 5}
+    { "print", Print, 1, 5, 5},
+    { "prog", Prog, 3, 4, 9},
+    { "call", Call, 10, 4, 5},
+    { "ls",   List, 0, 2, 9},
+    { "edit", Edit, 1, 4, 9},
+    { "del",  Del, 1, 3, 9}
 };
 
 #define NB_CONSTANTS 3
@@ -527,6 +534,11 @@ void print_element (element_t *root, int level)
     case While: func = "While"; break;
     case Prog: func = "Program"; break;
     case Print: func = "Print"; break;
+    case Prog: func = "Program"; break;
+    case Call: func = "Call"; break;
+    case List: func = "List"; break;
+    case Edit: func = "Edit"; break;
+    case Del: func = "Del"; break;
     }
 
     fprintf (stdout, "Function: %s\n", func);
@@ -719,6 +731,25 @@ void quit (void)
     exit (0);
 }
 
+/* program function */
+
+void prog (int id, int nbmems, element_t *root)
+{ }
+
+double call (int id, int nbobs, element_t **ops)
+{
+    return 0;
+}
+
+void list ()
+{ }
+
+void edit (int id)
+{ }
+
+void del (int id)
+{ }
+
 /* help message */
 
 void help (void)
@@ -801,6 +832,7 @@ double evaluate_element (element_t *root, char mask)
     case Lt:
     case And:
     case Or:
+    case Prog:
         if (root->ops[1]) {
             op1 = evaluate_element (root->ops[1], nextmask);
         } else if (root->func != Store) {
@@ -826,6 +858,10 @@ double evaluate_element (element_t *root, char mask)
     case Not:
     case Mem:
     case Cond:
+    case Call:
+    case List:
+    case Edit:
+    case Del:
         if (root->ops[0]) {
             op0 = evaluate_element (root->ops[0], 0);
         } else {
@@ -906,6 +942,11 @@ double evaluate_element (element_t *root, char mask)
     case While: return while_do (root->ops[0], root->ops[1]);
     case Prog: return program_do (root->ops, root->nbops);
     case Print: return print (op0);
+    case Prog: prog ((int)op0, (int)op1, root->ops[2]); break;
+    case Call: return call ((int)op0, root->nbops + 1, root->ops + 1);
+    case List: list (); break;
+    case Edit: edit ((int)op0); break;
+    case Del: del (int (op0)); break;
     }
 
     return 0;
index 2e3e6d464c6ffba87fab1c90f62ce41f5f9bf453..4907c67699a74dc69f5655065e5165df7ae8b072 100644 (file)
--- a/parser.h
+++ b/parser.h
@@ -20,7 +20,8 @@ typedef enum {
     Ans, E, Pi,
     Equal, Diff, Ge, Le, Gt, Lt,
     And, Or, Not,
-    Cond, While, Prog, Print
+    Cond, While, Prog, Print,
+    Prog, Call, List, Edit, Del
 } func_t;
 
 /* keyword type */
@@ -46,6 +47,15 @@ typedef struct _element_t {
 
 #define ERROR_OP ((element_t *)(-1))
 
+/* workspace type */
+
+typedef struct _workspace_t {
+    int id;
+    double answer;
+    double *storage;
+    element_t *root;
+} workspace_t;
+
 /* parser function */
 
 void delelement (element_t *root);