continue;
}
+ /* check for open brace */
+
+ if (*str == '{') {
+ VERBOSE (DEBUG, fprintf (stdout, "start processing brace\n"));
+ element_t *prog = newelement (Prog, 0, 5);
+ if (prog == NULL) {
+ delelement (root);
+ return ERROR_OP;
+ }
+ if (root == NULL) {
+ root = prog;
+ } else {
+ for (i = 0; i < root->nbops; i++) {
+ if (root->ops[i] == NULL) {
+ root->ops[i] = prog;
+ found = 1;
+ }
+ }
+ if (!found) {
+ delelement (prog);
+ delelement (root);
+ return ERROR_OP;
+ }
+ }
+
+ do {
+ found = 0;
+ new = parser (str + 1, &str, 0);
+ if ((new == NULL) || ((new != ERROR_OP) && (new->prio == 9))) {
+ delelement (new);
+ new = ERROR_OP;
+ }
+ if ((new == NULL) || (new == ERROR_OP)) {
+ delelement (root);
+ return ERROR_OP;
+ }
+ element_t *prognew = newelement (Prog, prog->nbops + 1, 5);
+ for (i = 0; i < prog->nbops; i++) {
+ prognew->ops[i] = prog->ops[i];
+ }
+ prog->ops[prog->nbops] = new;
+ delelement (prog);
+ prog = prognew;
+ } while (*str == ',');
+
+ if (*str != '}') {
+ delelement (root);
+ return ERROR_OP;
+ }
+ str++;
+ VERBOSE (DEBUG, fprintf (stdout, "stop processing brace\n"));
+ continue;
+ }
+
/* check for open bracket */
if (*str == '(') {
continue;
}
- /* check for closing bracket or koma */
+ /* check for closing bracket, closing brace or koma */
- if ((*str == ')') || (*str == ',')) {
+ if ((*str == ')') || (*str == '}') || (*str == ',')) {
if (next != NULL) {
*next = str;
}
case Not: func = "Not"; break;
case Cond: func = "Condition"; break;
case While: func = "While"; break;
+ case Prog: func = "Program"; break;
}
fprintf (stdout, "Function: %s\n", func);
return ret;
}
+/* program function */
+
+double program_do (element_t **prog, int nbcalls)
+{
+ double ret = 0;
+ int i;
+ for (i = 0; i < nbcalls; i++) {
+ ret = evaluate_element (prog[i], 0);
+ prog[i] = NULL;
+ }
+ return ret;
+}
+
/* quit function */
void quit (void)
case Ans:
case Pi:
case E:
+ case Prog:
break;
case While:
if (root->ops[0] == NULL) {
return 0;
}
case While: return while_do (root->ops[0], root->ops[1]);
+ case Prog: return program_do (root->ops, root->nbops);
}
return 0;